Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
9fafcd7b PM |
2 | #ifndef __NF_CONNTRACK_SIP_H__ |
3 | #define __NF_CONNTRACK_SIP_H__ | |
4 | #ifdef __KERNEL__ | |
5 | ||
1afc5679 PNA |
6 | #include <net/netfilter/nf_conntrack_expect.h> |
7 | ||
7266507d KC |
8 | #include <linux/types.h> |
9 | ||
9fafcd7b PM |
10 | #define SIP_PORT 5060 |
11 | #define SIP_TIMEOUT 3600 | |
12 | ||
0f32a40f PM |
13 | struct nf_ct_sip_master { |
14 | unsigned int register_cseq; | |
ef75d49f | 15 | unsigned int invite_cseq; |
7266507d | 16 | __be16 forced_dport; |
0f32a40f PM |
17 | }; |
18 | ||
19 | enum sip_expectation_classes { | |
20 | SIP_EXPECT_SIGNALLING, | |
21 | SIP_EXPECT_AUDIO, | |
0d0ab037 | 22 | SIP_EXPECT_VIDEO, |
9d288dff | 23 | SIP_EXPECT_IMAGE, |
0f32a40f PM |
24 | __SIP_EXPECT_MAX |
25 | }; | |
26 | #define SIP_EXPECT_MAX (__SIP_EXPECT_MAX - 1) | |
27 | ||
0d0ab037 PM |
28 | struct sdp_media_type { |
29 | const char *name; | |
30 | unsigned int len; | |
31 | enum sip_expectation_classes class; | |
32 | }; | |
33 | ||
34 | #define SDP_MEDIA_TYPE(__name, __class) \ | |
35 | { \ | |
36 | .name = (__name), \ | |
37 | .len = sizeof(__name) - 1, \ | |
38 | .class = (__class), \ | |
39 | } | |
40 | ||
30f33e6d PM |
41 | struct sip_handler { |
42 | const char *method; | |
43 | unsigned int len; | |
051966c0 PM |
44 | int (*request)(struct sk_buff *skb, unsigned int protoff, |
45 | unsigned int dataoff, | |
30f33e6d PM |
46 | const char **dptr, unsigned int *datalen, |
47 | unsigned int cseq); | |
051966c0 PM |
48 | int (*response)(struct sk_buff *skb, unsigned int protoff, |
49 | unsigned int dataoff, | |
30f33e6d PM |
50 | const char **dptr, unsigned int *datalen, |
51 | unsigned int cseq, unsigned int code); | |
52 | }; | |
53 | ||
54 | #define SIP_HANDLER(__method, __request, __response) \ | |
55 | { \ | |
56 | .method = (__method), \ | |
57 | .len = sizeof(__method) - 1, \ | |
58 | .request = (__request), \ | |
59 | .response = (__response), \ | |
60 | } | |
61 | ||
3e9b4600 PM |
62 | struct sip_header { |
63 | const char *name; | |
64 | const char *cname; | |
65 | const char *search; | |
66 | unsigned int len; | |
67 | unsigned int clen; | |
68 | unsigned int slen; | |
69 | int (*match_len)(const struct nf_conn *ct, | |
70 | const char *dptr, const char *limit, | |
71 | int *shift); | |
72 | }; | |
73 | ||
74 | #define __SIP_HDR(__name, __cname, __search, __match) \ | |
75 | { \ | |
76 | .name = (__name), \ | |
77 | .len = sizeof(__name) - 1, \ | |
78 | .cname = (__cname), \ | |
79 | .clen = (__cname) ? sizeof(__cname) - 1 : 0, \ | |
80 | .search = (__search), \ | |
81 | .slen = (__search) ? sizeof(__search) - 1 : 0, \ | |
82 | .match_len = (__match), \ | |
83 | } | |
84 | ||
ea45f12a PM |
85 | #define SIP_HDR(__name, __cname, __search, __match) \ |
86 | __SIP_HDR(__name, __cname, __search, __match) | |
87 | ||
3e9b4600 PM |
88 | #define SDP_HDR(__name, __search, __match) \ |
89 | __SIP_HDR(__name, NULL, __search, __match) | |
90 | ||
ea45f12a | 91 | enum sip_header_types { |
30f33e6d | 92 | SIP_HDR_CSEQ, |
ea45f12a PM |
93 | SIP_HDR_FROM, |
94 | SIP_HDR_TO, | |
95 | SIP_HDR_CONTACT, | |
f5b321bd PM |
96 | SIP_HDR_VIA_UDP, |
97 | SIP_HDR_VIA_TCP, | |
0f32a40f | 98 | SIP_HDR_EXPIRES, |
ea45f12a | 99 | SIP_HDR_CONTENT_LENGTH, |
001985b2 | 100 | SIP_HDR_CALL_ID, |
ea45f12a PM |
101 | }; |
102 | ||
3e9b4600 PM |
103 | enum sdp_header_types { |
104 | SDP_HDR_UNSPEC, | |
105 | SDP_HDR_VERSION, | |
9a664821 PM |
106 | SDP_HDR_OWNER, |
107 | SDP_HDR_CONNECTION, | |
3e9b4600 | 108 | SDP_HDR_MEDIA, |
9fafcd7b PM |
109 | }; |
110 | ||
180cf72f | 111 | struct nf_nat_sip_hooks { |
112 | unsigned int (*msg)(struct sk_buff *skb, | |
113 | unsigned int protoff, | |
114 | unsigned int dataoff, | |
115 | const char **dptr, | |
116 | unsigned int *datalen); | |
117 | ||
118 | void (*seq_adjust)(struct sk_buff *skb, | |
119 | unsigned int protoff, s16 off); | |
120 | ||
121 | unsigned int (*expect)(struct sk_buff *skb, | |
122 | unsigned int protoff, | |
123 | unsigned int dataoff, | |
124 | const char **dptr, | |
125 | unsigned int *datalen, | |
126 | struct nf_conntrack_expect *exp, | |
127 | unsigned int matchoff, | |
128 | unsigned int matchlen); | |
129 | ||
130 | unsigned int (*sdp_addr)(struct sk_buff *skb, | |
131 | unsigned int protoff, | |
132 | unsigned int dataoff, | |
133 | const char **dptr, | |
134 | unsigned int *datalen, | |
135 | unsigned int sdpoff, | |
136 | enum sdp_header_types type, | |
137 | enum sdp_header_types term, | |
138 | const union nf_inet_addr *addr); | |
139 | ||
140 | unsigned int (*sdp_port)(struct sk_buff *skb, | |
141 | unsigned int protoff, | |
142 | unsigned int dataoff, | |
143 | const char **dptr, | |
144 | unsigned int *datalen, | |
145 | unsigned int matchoff, | |
146 | unsigned int matchlen, | |
147 | u_int16_t port); | |
148 | ||
149 | unsigned int (*sdp_session)(struct sk_buff *skb, | |
150 | unsigned int protoff, | |
151 | unsigned int dataoff, | |
152 | const char **dptr, | |
153 | unsigned int *datalen, | |
154 | unsigned int sdpoff, | |
155 | const union nf_inet_addr *addr); | |
156 | ||
157 | unsigned int (*sdp_media)(struct sk_buff *skb, | |
158 | unsigned int protoff, | |
159 | unsigned int dataoff, | |
160 | const char **dptr, | |
161 | unsigned int *datalen, | |
162 | struct nf_conntrack_expect *rtp_exp, | |
163 | struct nf_conntrack_expect *rtcp_exp, | |
164 | unsigned int mediaoff, | |
165 | unsigned int medialen, | |
166 | union nf_inet_addr *rtp_addr); | |
167 | }; | |
168 | extern const struct nf_nat_sip_hooks *nf_nat_sip_hooks; | |
9fafcd7b | 169 | |
a0f4ecf3 JP |
170 | int ct_sip_parse_request(const struct nf_conn *ct, const char *dptr, |
171 | unsigned int datalen, unsigned int *matchoff, | |
172 | unsigned int *matchlen, union nf_inet_addr *addr, | |
173 | __be16 *port); | |
174 | int ct_sip_get_header(const struct nf_conn *ct, const char *dptr, | |
175 | unsigned int dataoff, unsigned int datalen, | |
176 | enum sip_header_types type, unsigned int *matchoff, | |
177 | unsigned int *matchlen); | |
178 | int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, | |
179 | unsigned int *dataoff, unsigned int datalen, | |
180 | enum sip_header_types type, int *in_header, | |
181 | unsigned int *matchoff, unsigned int *matchlen, | |
182 | union nf_inet_addr *addr, __be16 *port); | |
183 | int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr, | |
184 | unsigned int dataoff, unsigned int datalen, | |
185 | const char *name, unsigned int *matchoff, | |
186 | unsigned int *matchlen, union nf_inet_addr *addr, | |
187 | bool delim); | |
188 | int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr, | |
189 | unsigned int off, unsigned int datalen, | |
190 | const char *name, unsigned int *matchoff, | |
191 | unsigned int *matchen, unsigned int *val); | |
192 | ||
193 | int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr, | |
194 | unsigned int dataoff, unsigned int datalen, | |
195 | enum sdp_header_types type, | |
196 | enum sdp_header_types term, | |
197 | unsigned int *matchoff, unsigned int *matchlen); | |
3e9b4600 | 198 | |
9fafcd7b PM |
199 | #endif /* __KERNEL__ */ |
200 | #endif /* __NF_CONNTRACK_SIP_H__ */ |