netfilter: xt_conntrack: support matching on port ranges
[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_IMAGE,
18         __SIP_EXPECT_MAX
19 };
20 #define SIP_EXPECT_MAX  (__SIP_EXPECT_MAX - 1)
21
22 struct sdp_media_type {
23         const char                      *name;
24         unsigned int                    len;
25         enum sip_expectation_classes    class;
26 };
27
28 #define SDP_MEDIA_TYPE(__name, __class)                                 \
29 {                                                                       \
30         .name   = (__name),                                             \
31         .len    = sizeof(__name) - 1,                                   \
32         .class  = (__class),                                            \
33 }
34
35 struct sip_handler {
36         const char      *method;
37         unsigned int    len;
38         int             (*request)(struct sk_buff *skb, unsigned int dataoff,
39                                    const char **dptr, unsigned int *datalen,
40                                    unsigned int cseq);
41         int             (*response)(struct sk_buff *skb, unsigned int dataoff,
42                                     const char **dptr, unsigned int *datalen,
43                                     unsigned int cseq, unsigned int code);
44 };
45
46 #define SIP_HANDLER(__method, __request, __response)                    \
47 {                                                                       \
48         .method         = (__method),                                   \
49         .len            = sizeof(__method) - 1,                         \
50         .request        = (__request),                                  \
51         .response       = (__response),                                 \
52 }
53
54 struct sip_header {
55         const char      *name;
56         const char      *cname;
57         const char      *search;
58         unsigned int    len;
59         unsigned int    clen;
60         unsigned int    slen;
61         int             (*match_len)(const struct nf_conn *ct,
62                                      const char *dptr, const char *limit,
63                                      int *shift);
64 };
65
66 #define __SIP_HDR(__name, __cname, __search, __match)                   \
67 {                                                                       \
68         .name           = (__name),                                     \
69         .len            = sizeof(__name) - 1,                           \
70         .cname          = (__cname),                                    \
71         .clen           = (__cname) ? sizeof(__cname) - 1 : 0,          \
72         .search         = (__search),                                   \
73         .slen           = (__search) ? sizeof(__search) - 1 : 0,        \
74         .match_len      = (__match),                                    \
75 }
76
77 #define SIP_HDR(__name, __cname, __search, __match) \
78         __SIP_HDR(__name, __cname, __search, __match)
79
80 #define SDP_HDR(__name, __search, __match) \
81         __SIP_HDR(__name, NULL, __search, __match)
82
83 enum sip_header_types {
84         SIP_HDR_CSEQ,
85         SIP_HDR_FROM,
86         SIP_HDR_TO,
87         SIP_HDR_CONTACT,
88         SIP_HDR_VIA_UDP,
89         SIP_HDR_VIA_TCP,
90         SIP_HDR_EXPIRES,
91         SIP_HDR_CONTENT_LENGTH,
92         SIP_HDR_CALL_ID,
93 };
94
95 enum sdp_header_types {
96         SDP_HDR_UNSPEC,
97         SDP_HDR_VERSION,
98         SDP_HDR_OWNER_IP4,
99         SDP_HDR_CONNECTION_IP4,
100         SDP_HDR_OWNER_IP6,
101         SDP_HDR_CONNECTION_IP6,
102         SDP_HDR_MEDIA,
103 };
104
105 extern unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb,
106                                        unsigned int dataoff,
107                                        const char **dptr,
108                                        unsigned int *datalen);
109 extern void (*nf_nat_sip_seq_adjust_hook)(struct sk_buff *skb, s16 off);
110 extern unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb,
111                                               unsigned int dataoff,
112                                               const char **dptr,
113                                               unsigned int *datalen,
114                                               struct nf_conntrack_expect *exp,
115                                               unsigned int matchoff,
116                                               unsigned int matchlen);
117 extern unsigned int (*nf_nat_sdp_addr_hook)(struct sk_buff *skb,
118                                             unsigned int dataoff,
119                                             const char **dptr,
120                                             unsigned int *datalen,
121                                             unsigned int sdpoff,
122                                             enum sdp_header_types type,
123                                             enum sdp_header_types term,
124                                             const union nf_inet_addr *addr);
125 extern unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb,
126                                             unsigned int dataoff,
127                                             const char **dptr,
128                                             unsigned int *datalen,
129                                             unsigned int matchoff,
130                                             unsigned int matchlen,
131                                             u_int16_t port);
132 extern unsigned int (*nf_nat_sdp_session_hook)(struct sk_buff *skb,
133                                                unsigned int dataoff,
134                                                const char **dptr,
135                                                unsigned int *datalen,
136                                                unsigned int sdpoff,
137                                                const union nf_inet_addr *addr);
138 extern unsigned int (*nf_nat_sdp_media_hook)(struct sk_buff *skb,
139                                              unsigned int dataoff,
140                                              const char **dptr,
141                                              unsigned int *datalen,
142                                              struct nf_conntrack_expect *rtp_exp,
143                                              struct nf_conntrack_expect *rtcp_exp,
144                                              unsigned int mediaoff,
145                                              unsigned int medialen,
146                                              union nf_inet_addr *rtp_addr);
147
148 extern int ct_sip_parse_request(const struct nf_conn *ct,
149                                 const char *dptr, unsigned int datalen,
150                                 unsigned int *matchoff, unsigned int *matchlen,
151                                 union nf_inet_addr *addr, __be16 *port);
152 extern int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
153                              unsigned int dataoff, unsigned int datalen,
154                              enum sip_header_types type,
155                              unsigned int *matchoff, unsigned int *matchlen);
156 extern int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,
157                                    unsigned int *dataoff, unsigned int datalen,
158                                    enum sip_header_types type, int *in_header,
159                                    unsigned int *matchoff, unsigned int *matchlen,
160                                    union nf_inet_addr *addr, __be16 *port);
161 extern int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr,
162                                       unsigned int dataoff, unsigned int datalen,
163                                       const char *name,
164                                       unsigned int *matchoff, unsigned int *matchlen,
165                                       union nf_inet_addr *addr);
166 extern int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,
167                                         unsigned int off, unsigned int datalen,
168                                         const char *name,
169                                         unsigned int *matchoff, unsigned int *matchen,
170                                         unsigned int *val);
171
172 extern int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr,
173                                  unsigned int dataoff, unsigned int datalen,
174                                  enum sdp_header_types type,
175                                  enum sdp_header_types term,
176                                  unsigned int *matchoff, unsigned int *matchlen);
177
178 #endif /* __KERNEL__ */
179 #endif /* __NF_CONNTRACK_SIP_H__ */