blob: d5af3c27fb7de0385b11396ac241991bacb3684e [file] [log] [blame]
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001#ifndef __NF_CONNTRACK_SIP_H__
2#define __NF_CONNTRACK_SIP_H__
3#ifdef __KERNEL__
4
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02005#include <net/netfilter/nf_conntrack_expect.h>
6
Kevin Cernekee72665072012-12-17 18:33:58 +00007#include <linux/types.h>
8
Patrick McHardy9fafcd72006-12-02 22:09:57 -08009#define SIP_PORT 5060
10#define SIP_TIMEOUT 3600
11
Patrick McHardy0f32a402008-03-25 20:25:13 -070012struct nf_ct_sip_master {
13 unsigned int register_cseq;
Patrick McHardyef75d492008-05-08 01:15:21 -070014 unsigned int invite_cseq;
Kevin Cernekee72665072012-12-17 18:33:58 +000015 __be16 forced_dport;
Patrick McHardy0f32a402008-03-25 20:25:13 -070016};
17
18enum sip_expectation_classes {
19 SIP_EXPECT_SIGNALLING,
20 SIP_EXPECT_AUDIO,
Patrick McHardy0d0ab032008-03-25 20:26:24 -070021 SIP_EXPECT_VIDEO,
Patrick McHardy9d288df2010-02-11 12:30:21 +010022 SIP_EXPECT_IMAGE,
Patrick McHardy0f32a402008-03-25 20:25:13 -070023 __SIP_EXPECT_MAX
24};
25#define SIP_EXPECT_MAX (__SIP_EXPECT_MAX - 1)
26
Patrick McHardy0d0ab032008-03-25 20:26:24 -070027struct sdp_media_type {
28 const char *name;
29 unsigned int len;
30 enum sip_expectation_classes class;
31};
32
33#define SDP_MEDIA_TYPE(__name, __class) \
34{ \
35 .name = (__name), \
36 .len = sizeof(__name) - 1, \
37 .class = (__class), \
38}
39
Patrick McHardy30f33e62008-03-25 20:22:20 -070040struct sip_handler {
41 const char *method;
42 unsigned int len;
Patrick McHardy051966c2012-08-26 19:14:04 +020043 int (*request)(struct sk_buff *skb, unsigned int protoff,
44 unsigned int dataoff,
Patrick McHardy30f33e62008-03-25 20:22:20 -070045 const char **dptr, unsigned int *datalen,
46 unsigned int cseq);
Patrick McHardy051966c2012-08-26 19:14:04 +020047 int (*response)(struct sk_buff *skb, unsigned int protoff,
48 unsigned int dataoff,
Patrick McHardy30f33e62008-03-25 20:22:20 -070049 const char **dptr, unsigned int *datalen,
50 unsigned int cseq, unsigned int code);
51};
52
53#define SIP_HANDLER(__method, __request, __response) \
54{ \
55 .method = (__method), \
56 .len = sizeof(__method) - 1, \
57 .request = (__request), \
58 .response = (__response), \
59}
60
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -070061struct sip_header {
62 const char *name;
63 const char *cname;
64 const char *search;
65 unsigned int len;
66 unsigned int clen;
67 unsigned int slen;
68 int (*match_len)(const struct nf_conn *ct,
69 const char *dptr, const char *limit,
70 int *shift);
71};
72
73#define __SIP_HDR(__name, __cname, __search, __match) \
74{ \
75 .name = (__name), \
76 .len = sizeof(__name) - 1, \
77 .cname = (__cname), \
78 .clen = (__cname) ? sizeof(__cname) - 1 : 0, \
79 .search = (__search), \
80 .slen = (__search) ? sizeof(__search) - 1 : 0, \
81 .match_len = (__match), \
82}
83
Patrick McHardyea45f122008-03-25 20:18:57 -070084#define SIP_HDR(__name, __cname, __search, __match) \
85 __SIP_HDR(__name, __cname, __search, __match)
86
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -070087#define SDP_HDR(__name, __search, __match) \
88 __SIP_HDR(__name, NULL, __search, __match)
89
Patrick McHardyea45f122008-03-25 20:18:57 -070090enum sip_header_types {
Patrick McHardy30f33e62008-03-25 20:22:20 -070091 SIP_HDR_CSEQ,
Patrick McHardyea45f122008-03-25 20:18:57 -070092 SIP_HDR_FROM,
93 SIP_HDR_TO,
94 SIP_HDR_CONTACT,
Patrick McHardyf5b321b2010-02-11 12:26:19 +010095 SIP_HDR_VIA_UDP,
96 SIP_HDR_VIA_TCP,
Patrick McHardy0f32a402008-03-25 20:25:13 -070097 SIP_HDR_EXPIRES,
Patrick McHardyea45f122008-03-25 20:18:57 -070098 SIP_HDR_CONTENT_LENGTH,
Simon Horman001985b2010-08-22 21:37:51 +090099 SIP_HDR_CALL_ID,
Patrick McHardyea45f122008-03-25 20:18:57 -0700100};
101
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700102enum sdp_header_types {
103 SDP_HDR_UNSPEC,
104 SDP_HDR_VERSION,
Patrick McHardy9a664822012-08-26 19:14:25 +0200105 SDP_HDR_OWNER,
106 SDP_HDR_CONNECTION,
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700107 SDP_HDR_MEDIA,
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800108};
109
holger@eitzenberger.org180cf722013-09-30 17:07:28 +0200110struct nf_nat_sip_hooks {
111 unsigned int (*msg)(struct sk_buff *skb,
112 unsigned int protoff,
113 unsigned int dataoff,
114 const char **dptr,
115 unsigned int *datalen);
116
117 void (*seq_adjust)(struct sk_buff *skb,
118 unsigned int protoff, s16 off);
119
120 unsigned int (*expect)(struct sk_buff *skb,
121 unsigned int protoff,
122 unsigned int dataoff,
123 const char **dptr,
124 unsigned int *datalen,
125 struct nf_conntrack_expect *exp,
126 unsigned int matchoff,
127 unsigned int matchlen);
128
129 unsigned int (*sdp_addr)(struct sk_buff *skb,
130 unsigned int protoff,
131 unsigned int dataoff,
132 const char **dptr,
133 unsigned int *datalen,
134 unsigned int sdpoff,
135 enum sdp_header_types type,
136 enum sdp_header_types term,
137 const union nf_inet_addr *addr);
138
139 unsigned int (*sdp_port)(struct sk_buff *skb,
140 unsigned int protoff,
141 unsigned int dataoff,
142 const char **dptr,
143 unsigned int *datalen,
144 unsigned int matchoff,
145 unsigned int matchlen,
146 u_int16_t port);
147
148 unsigned int (*sdp_session)(struct sk_buff *skb,
149 unsigned int protoff,
150 unsigned int dataoff,
151 const char **dptr,
152 unsigned int *datalen,
153 unsigned int sdpoff,
154 const union nf_inet_addr *addr);
155
156 unsigned int (*sdp_media)(struct sk_buff *skb,
157 unsigned int protoff,
158 unsigned int dataoff,
159 const char **dptr,
160 unsigned int *datalen,
161 struct nf_conntrack_expect *rtp_exp,
162 struct nf_conntrack_expect *rtcp_exp,
163 unsigned int mediaoff,
164 unsigned int medialen,
165 union nf_inet_addr *rtp_addr);
166};
167extern const struct nf_nat_sip_hooks *nf_nat_sip_hooks;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800168
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700169int ct_sip_parse_request(const struct nf_conn *ct, const char *dptr,
170 unsigned int datalen, unsigned int *matchoff,
171 unsigned int *matchlen, union nf_inet_addr *addr,
172 __be16 *port);
173int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
174 unsigned int dataoff, unsigned int datalen,
175 enum sip_header_types type, unsigned int *matchoff,
176 unsigned int *matchlen);
177int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,
178 unsigned int *dataoff, unsigned int datalen,
179 enum sip_header_types type, int *in_header,
180 unsigned int *matchoff, unsigned int *matchlen,
181 union nf_inet_addr *addr, __be16 *port);
182int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr,
183 unsigned int dataoff, unsigned int datalen,
184 const char *name, unsigned int *matchoff,
185 unsigned int *matchlen, union nf_inet_addr *addr,
186 bool delim);
187int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,
188 unsigned int off, unsigned int datalen,
189 const char *name, unsigned int *matchoff,
190 unsigned int *matchen, unsigned int *val);
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700191
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700192int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr,
193 unsigned int dataoff, unsigned int datalen,
194 enum sdp_header_types type,
195 enum sdp_header_types term,
196 unsigned int *matchoff, unsigned int *matchlen);
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700197
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800198#endif /* __KERNEL__ */
199#endif /* __NF_CONNTRACK_SIP_H__ */