netfilter: nf_conntrack_sip: restrict RTP expect flushing on error to last request
[linux-2.6.git] / include / linux / netfilter / nf_conntrack_sip.h
1 #ifndef __NF_CONNTRACK_SIP_H__
2 #define __NF_CONNTRACK_SIP_H__
3 #ifdef __KERNEL__
4
5 #define SIP_PORT        5060
6 #define SIP_TIMEOUT     3600
7
8 struct nf_ct_sip_master {
9         unsigned int    register_cseq;
10         unsigned int    invite_cseq;
11 };
12
13 enum sip_expectation_classes {
14         SIP_EXPECT_SIGNALLING,
15         SIP_EXPECT_AUDIO,
16         SIP_EXPECT_VIDEO,
17         __SIP_EXPECT_MAX
18 };
19 #define SIP_EXPECT_MAX  (__SIP_EXPECT_MAX - 1)
20
21 struct sdp_media_type {
22         const char                      *name;
23         unsigned int                    len;
24         enum sip_expectation_classes    class;
25 };
26
27 #define SDP_MEDIA_TYPE(__name, __class)                                 \
28 {                                                                       \
29         .name   = (__name),                                             \
30         .len    = sizeof(__name) - 1,                                   \
31         .class  = (__class),                                            \
32 }
33
34 struct sip_handler {
35         const char      *method;
36         unsigned int    len;
37         int             (*request)(struct sk_buff *skb,
38                                    const char **dptr, unsigned int *datalen,
39                                    unsigned int cseq);
40         int             (*response)(struct sk_buff *skb,
41                                     const char **dptr, unsigned int *datalen,
42                                     unsigned int cseq, unsigned int code);
43 };
44
45 #define SIP_HANDLER(__method, __request, __response)                    \
46 {                                                                       \
47         .method         = (__method),                                   \
48         .len            = sizeof(__method) - 1,                         \
49         .request        = (__request),                                  \
50         .response       = (__response),                                 \
51 }
52
53 struct sip_header {
54         const char      *name;
55         const char      *cname;
56         const char      *search;
57         unsigned int    len;
58         unsigned int    clen;
59         unsigned int    slen;
60         int             (*match_len)(const struct nf_conn *ct,
61                                      const char *dptr, const char *limit,
62                                      int *shift);
63 };
64
65 #define __SIP_HDR(__name, __cname, __search, __match)                   \
66 {                                                                       \
67         .name           = (__name),                                     \
68         .len            = sizeof(__name) - 1,                           \
69         .cname          = (__cname),                                    \
70         .clen           = (__cname) ? sizeof(__cname) - 1 : 0,          \
71         .search         = (__search),                                   \
72         .slen           = (__search) ? sizeof(__search) - 1 : 0,        \
73         .match_len      = (__match),                                    \
74 }
75
76 #define SIP_HDR(__name, __cname, __search, __match) \
77         __SIP_HDR(__name, __cname, __search, __match)
78
79 #define SDP_HDR(__name, __search, __match) \
80         __SIP_HDR(__name, NULL, __search, __match)
81
82 enum sip_header_types {
83         SIP_HDR_CSEQ,
84         SIP_HDR_FROM,
85         SIP_HDR_TO,
86         SIP_HDR_CONTACT,
87         SIP_HDR_VIA,
88         SIP_HDR_EXPIRES,
89         SIP_HDR_CONTENT_LENGTH,
90 };
91
92 enum sdp_header_types {
93         SDP_HDR_UNSPEC,
94         SDP_HDR_VERSION,
95         SDP_HDR_OWNER_IP4,
96         SDP_HDR_CONNECTION_IP4,
97         SDP_HDR_OWNER_IP6,
98         SDP_HDR_CONNECTION_IP6,
99         SDP_HDR_MEDIA,
100 };
101
102 extern unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb,
103                                        const char **dptr,
104                                        unsigned int *datalen);
105 extern unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb,
106                                               const char **dptr,
107                                               unsigned int *datalen,
108                                               struct nf_conntrack_expect *exp,
109                                               unsigned int matchoff,
110                                               unsigned int matchlen);
111 extern unsigned int (*nf_nat_sdp_addr_hook)(struct sk_buff *skb,
112                                             const char **dptr,
113                                             unsigned int dataoff,
114                                             unsigned int *datalen,
115                                             enum sdp_header_types type,
116                                             enum sdp_header_types term,
117                                             const union nf_inet_addr *addr);
118 extern unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb,
119                                             const char **dptr,
120                                             unsigned int *datalen,
121                                             unsigned int matchoff,
122                                             unsigned int matchlen,
123                                             u_int16_t port);
124 extern unsigned int (*nf_nat_sdp_session_hook)(struct sk_buff *skb,
125                                                const char **dptr,
126                                                unsigned int dataoff,
127                                                unsigned int *datalen,
128                                                const union nf_inet_addr *addr);
129 extern unsigned int (*nf_nat_sdp_media_hook)(struct sk_buff *skb,
130                                              const char **dptr,
131                                              unsigned int *datalen,
132                                              struct nf_conntrack_expect *rtp_exp,
133                                              struct nf_conntrack_expect *rtcp_exp,
134                                              unsigned int mediaoff,
135                                              unsigned int medialen,
136                                              union nf_inet_addr *rtp_addr);
137
138 extern int ct_sip_parse_request(const struct nf_conn *ct,
139                                 const char *dptr, unsigned int datalen,
140                                 unsigned int *matchoff, unsigned int *matchlen,
141                                 union nf_inet_addr *addr, __be16 *port);
142 extern int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
143                              unsigned int dataoff, unsigned int datalen,
144                              enum sip_header_types type,
145                              unsigned int *matchoff, unsigned int *matchlen);
146 extern int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,
147                                    unsigned int *dataoff, unsigned int datalen,
148                                    enum sip_header_types type, int *in_header,
149                                    unsigned int *matchoff, unsigned int *matchlen,
150                                    union nf_inet_addr *addr, __be16 *port);
151 extern int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr,
152                                       unsigned int dataoff, unsigned int datalen,
153                                       const char *name,
154                                       unsigned int *matchoff, unsigned int *matchlen,
155                                       union nf_inet_addr *addr);
156 extern int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,
157                                         unsigned int off, unsigned int datalen,
158                                         const char *name,
159                                         unsigned int *matchoff, unsigned int *matchen,
160                                         unsigned int *val);
161
162 extern int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr,
163                                  unsigned int dataoff, unsigned int datalen,
164                                  enum sdp_header_types type,
165                                  enum sdp_header_types term,
166                                  unsigned int *matchoff, unsigned int *matchlen);
167
168 #endif /* __KERNEL__ */
169 #endif /* __NF_CONNTRACK_SIP_H__ */