diff options
author | Patrick McHardy <kaber@trash.net> | 2006-11-28 20:35:26 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:31:23 -0500 |
commit | 9d5b8baa4e9ace9be113c6151aaeeb3c07a26fc8 (patch) | |
tree | 039d42ebf4734e665ccf4f9251668d31b10fdf2a /net/ipv4 | |
parent | 337fbc4166967a72c3cc71c597bdde7e6a8633ab (diff) |
[NETFILTER]: sip conntrack: minor cleanup
- Use enum for header field enumeration
- Use numerical value instead of pointer to header info structure to
identify headers, unexport ct_sip_hdrs
- group SIP and SDP entries in header info structure
- remove double forward declaration of ct_sip_get_info
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/netfilter/ip_conntrack_sip.c | 60 | ||||
-rw-r--r-- | net/ipv4/netfilter/ip_nat_sip.c | 30 |
2 files changed, 45 insertions, 45 deletions
diff --git a/net/ipv4/netfilter/ip_conntrack_sip.c b/net/ipv4/netfilter/ip_conntrack_sip.c index bf423db4ed46..cc3176581667 100644 --- a/net/ipv4/netfilter/ip_conntrack_sip.c +++ b/net/ipv4/netfilter/ip_conntrack_sip.c | |||
@@ -52,20 +52,32 @@ unsigned int (*ip_nat_sdp_hook)(struct sk_buff **pskb, | |||
52 | const char *dptr); | 52 | const char *dptr); |
53 | EXPORT_SYMBOL_GPL(ip_nat_sdp_hook); | 53 | EXPORT_SYMBOL_GPL(ip_nat_sdp_hook); |
54 | 54 | ||
55 | int ct_sip_get_info(const char *dptr, size_t dlen, | ||
56 | unsigned int *matchoff, | ||
57 | unsigned int *matchlen, | ||
58 | struct sip_header_nfo *hnfo); | ||
59 | EXPORT_SYMBOL_GPL(ct_sip_get_info); | ||
60 | |||
61 | |||
62 | static int digits_len(const char *dptr, const char *limit, int *shift); | 55 | static int digits_len(const char *dptr, const char *limit, int *shift); |
63 | static int epaddr_len(const char *dptr, const char *limit, int *shift); | 56 | static int epaddr_len(const char *dptr, const char *limit, int *shift); |
64 | static int skp_digits_len(const char *dptr, const char *limit, int *shift); | 57 | static int skp_digits_len(const char *dptr, const char *limit, int *shift); |
65 | static int skp_epaddr_len(const char *dptr, const char *limit, int *shift); | 58 | static int skp_epaddr_len(const char *dptr, const char *limit, int *shift); |
66 | 59 | ||
67 | struct sip_header_nfo ct_sip_hdrs[] = { | 60 | struct sip_header_nfo { |
68 | { /* Via header */ | 61 | const char *lname; |
62 | const char *sname; | ||
63 | const char *ln_str; | ||
64 | size_t lnlen; | ||
65 | size_t snlen; | ||
66 | size_t ln_strlen; | ||
67 | int (*match_len)(const char *, const char *, int *); | ||
68 | }; | ||
69 | |||
70 | static struct sip_header_nfo ct_sip_hdrs[] = { | ||
71 | [POS_REQ_HEADER] = { /* SIP Requests headers */ | ||
72 | .lname = "sip:", | ||
73 | .lnlen = sizeof("sip:") - 1, | ||
74 | .sname = "sip:", | ||
75 | .snlen = sizeof("sip:") - 1, /* yes, i know.. ;) */ | ||
76 | .ln_str = "@", | ||
77 | .ln_strlen = sizeof("@") - 1, | ||
78 | .match_len = epaddr_len | ||
79 | }, | ||
80 | [POS_VIA] = { /* SIP Via header */ | ||
69 | .lname = "Via:", | 81 | .lname = "Via:", |
70 | .lnlen = sizeof("Via:") - 1, | 82 | .lnlen = sizeof("Via:") - 1, |
71 | .sname = "\r\nv:", | 83 | .sname = "\r\nv:", |
@@ -74,7 +86,7 @@ struct sip_header_nfo ct_sip_hdrs[] = { | |||
74 | .ln_strlen = sizeof("UDP ") - 1, | 86 | .ln_strlen = sizeof("UDP ") - 1, |
75 | .match_len = epaddr_len, | 87 | .match_len = epaddr_len, |
76 | }, | 88 | }, |
77 | { /* Contact header */ | 89 | [POS_CONTACT] = { /* SIP Contact header */ |
78 | .lname = "Contact:", | 90 | .lname = "Contact:", |
79 | .lnlen = sizeof("Contact:") - 1, | 91 | .lnlen = sizeof("Contact:") - 1, |
80 | .sname = "\r\nm:", | 92 | .sname = "\r\nm:", |
@@ -83,7 +95,7 @@ struct sip_header_nfo ct_sip_hdrs[] = { | |||
83 | .ln_strlen = sizeof("sip:") - 1, | 95 | .ln_strlen = sizeof("sip:") - 1, |
84 | .match_len = skp_epaddr_len | 96 | .match_len = skp_epaddr_len |
85 | }, | 97 | }, |
86 | { /* Content length header */ | 98 | [POS_CONTENT] = { /* SIP Content length header */ |
87 | .lname = "Content-Length:", | 99 | .lname = "Content-Length:", |
88 | .lnlen = sizeof("Content-Length:") - 1, | 100 | .lnlen = sizeof("Content-Length:") - 1, |
89 | .sname = "\r\nl:", | 101 | .sname = "\r\nl:", |
@@ -92,7 +104,7 @@ struct sip_header_nfo ct_sip_hdrs[] = { | |||
92 | .ln_strlen = sizeof(":") - 1, | 104 | .ln_strlen = sizeof(":") - 1, |
93 | .match_len = skp_digits_len | 105 | .match_len = skp_digits_len |
94 | }, | 106 | }, |
95 | { /* SDP media info */ | 107 | [POS_MEDIA] = { /* SDP media info */ |
96 | .lname = "\nm=", | 108 | .lname = "\nm=", |
97 | .lnlen = sizeof("\nm=") - 1, | 109 | .lnlen = sizeof("\nm=") - 1, |
98 | .sname = "\rm=", | 110 | .sname = "\rm=", |
@@ -101,7 +113,7 @@ struct sip_header_nfo ct_sip_hdrs[] = { | |||
101 | .ln_strlen = sizeof("audio ") - 1, | 113 | .ln_strlen = sizeof("audio ") - 1, |
102 | .match_len = digits_len | 114 | .match_len = digits_len |
103 | }, | 115 | }, |
104 | { /* SDP owner address*/ | 116 | [POS_OWNER] = { /* SDP owner address*/ |
105 | .lname = "\no=", | 117 | .lname = "\no=", |
106 | .lnlen = sizeof("\no=") - 1, | 118 | .lnlen = sizeof("\no=") - 1, |
107 | .sname = "\ro=", | 119 | .sname = "\ro=", |
@@ -110,7 +122,7 @@ struct sip_header_nfo ct_sip_hdrs[] = { | |||
110 | .ln_strlen = sizeof("IN IP4 ") - 1, | 122 | .ln_strlen = sizeof("IN IP4 ") - 1, |
111 | .match_len = epaddr_len | 123 | .match_len = epaddr_len |
112 | }, | 124 | }, |
113 | { /* SDP connection info */ | 125 | [POS_CONNECTION] = { /* SDP connection info */ |
114 | .lname = "\nc=", | 126 | .lname = "\nc=", |
115 | .lnlen = sizeof("\nc=") - 1, | 127 | .lnlen = sizeof("\nc=") - 1, |
116 | .sname = "\rc=", | 128 | .sname = "\rc=", |
@@ -119,16 +131,7 @@ struct sip_header_nfo ct_sip_hdrs[] = { | |||
119 | .ln_strlen = sizeof("IN IP4 ") - 1, | 131 | .ln_strlen = sizeof("IN IP4 ") - 1, |
120 | .match_len = epaddr_len | 132 | .match_len = epaddr_len |
121 | }, | 133 | }, |
122 | { /* Requests headers */ | 134 | [POS_SDP_HEADER] = { /* SDP version header */ |
123 | .lname = "sip:", | ||
124 | .lnlen = sizeof("sip:") - 1, | ||
125 | .sname = "sip:", | ||
126 | .snlen = sizeof("sip:") - 1, /* yes, i know.. ;) */ | ||
127 | .ln_str = "@", | ||
128 | .ln_strlen = sizeof("@") - 1, | ||
129 | .match_len = epaddr_len | ||
130 | }, | ||
131 | { /* SDP version header */ | ||
132 | .lname = "\nv=", | 135 | .lname = "\nv=", |
133 | .lnlen = sizeof("\nv=") - 1, | 136 | .lnlen = sizeof("\nv=") - 1, |
134 | .sname = "\rv=", | 137 | .sname = "\rv=", |
@@ -138,7 +141,6 @@ struct sip_header_nfo ct_sip_hdrs[] = { | |||
138 | .match_len = digits_len | 141 | .match_len = digits_len |
139 | } | 142 | } |
140 | }; | 143 | }; |
141 | EXPORT_SYMBOL_GPL(ct_sip_hdrs); | ||
142 | 144 | ||
143 | /* get line lenght until first CR or LF seen. */ | 145 | /* get line lenght until first CR or LF seen. */ |
144 | int ct_sip_lnlen(const char *line, const char *limit) | 146 | int ct_sip_lnlen(const char *line, const char *limit) |
@@ -263,8 +265,9 @@ static int skp_epaddr_len(const char *dptr, const char *limit, int *shift) | |||
263 | int ct_sip_get_info(const char *dptr, size_t dlen, | 265 | int ct_sip_get_info(const char *dptr, size_t dlen, |
264 | unsigned int *matchoff, | 266 | unsigned int *matchoff, |
265 | unsigned int *matchlen, | 267 | unsigned int *matchlen, |
266 | struct sip_header_nfo *hnfo) | 268 | enum sip_header_pos pos) |
267 | { | 269 | { |
270 | struct sip_header_nfo *hnfo = &ct_sip_hdrs[pos]; | ||
268 | const char *limit, *aux, *k = dptr; | 271 | const char *limit, *aux, *k = dptr; |
269 | int shift = 0; | 272 | int shift = 0; |
270 | 273 | ||
@@ -298,6 +301,7 @@ int ct_sip_get_info(const char *dptr, size_t dlen, | |||
298 | DEBUGP("%s header not found.\n", hnfo->lname); | 301 | DEBUGP("%s header not found.\n", hnfo->lname); |
299 | return 0; | 302 | return 0; |
300 | } | 303 | } |
304 | EXPORT_SYMBOL_GPL(ct_sip_get_info); | ||
301 | 305 | ||
302 | static int set_expected_rtp(struct sk_buff **pskb, | 306 | static int set_expected_rtp(struct sk_buff **pskb, |
303 | struct ip_conntrack *ct, | 307 | struct ip_conntrack *ct, |
@@ -393,7 +397,7 @@ static int sip_help(struct sk_buff **pskb, | |||
393 | } | 397 | } |
394 | /* Get ip and port address from SDP packet. */ | 398 | /* Get ip and port address from SDP packet. */ |
395 | if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen, | 399 | if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen, |
396 | &ct_sip_hdrs[POS_CONNECTION]) > 0) { | 400 | POS_CONNECTION) > 0) { |
397 | 401 | ||
398 | /* We'll drop only if there are parse problems. */ | 402 | /* We'll drop only if there are parse problems. */ |
399 | if (parse_ipaddr(dptr + matchoff, NULL, &ipaddr, | 403 | if (parse_ipaddr(dptr + matchoff, NULL, &ipaddr, |
@@ -402,7 +406,7 @@ static int sip_help(struct sk_buff **pskb, | |||
402 | goto out; | 406 | goto out; |
403 | } | 407 | } |
404 | if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen, | 408 | if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen, |
405 | &ct_sip_hdrs[POS_MEDIA]) > 0) { | 409 | POS_MEDIA) > 0) { |
406 | 410 | ||
407 | port = simple_strtoul(dptr + matchoff, NULL, 10); | 411 | port = simple_strtoul(dptr + matchoff, NULL, 10); |
408 | if (port < 1024) { | 412 | if (port < 1024) { |
diff --git a/net/ipv4/netfilter/ip_nat_sip.c b/net/ipv4/netfilter/ip_nat_sip.c index 9fad98099532..47097aac63d8 100644 --- a/net/ipv4/netfilter/ip_nat_sip.c +++ b/net/ipv4/netfilter/ip_nat_sip.c | |||
@@ -29,18 +29,16 @@ MODULE_DESCRIPTION("SIP NAT helper"); | |||
29 | #define DEBUGP(format, args...) | 29 | #define DEBUGP(format, args...) |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | extern struct sip_header_nfo ct_sip_hdrs[]; | ||
33 | |||
34 | static unsigned int mangle_sip_packet(struct sk_buff **pskb, | 32 | static unsigned int mangle_sip_packet(struct sk_buff **pskb, |
35 | enum ip_conntrack_info ctinfo, | 33 | enum ip_conntrack_info ctinfo, |
36 | struct ip_conntrack *ct, | 34 | struct ip_conntrack *ct, |
37 | const char **dptr, size_t dlen, | 35 | const char **dptr, size_t dlen, |
38 | char *buffer, int bufflen, | 36 | char *buffer, int bufflen, |
39 | struct sip_header_nfo *hnfo) | 37 | enum sip_header_pos pos) |
40 | { | 38 | { |
41 | unsigned int matchlen, matchoff; | 39 | unsigned int matchlen, matchoff; |
42 | 40 | ||
43 | if (ct_sip_get_info(*dptr, dlen, &matchoff, &matchlen, hnfo) <= 0) | 41 | if (ct_sip_get_info(*dptr, dlen, &matchoff, &matchlen, pos) <= 0) |
44 | return 0; | 42 | return 0; |
45 | 43 | ||
46 | if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo, | 44 | if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo, |
@@ -80,14 +78,13 @@ static unsigned int ip_nat_sip(struct sk_buff **pskb, | |||
80 | if ((ctinfo) < IP_CT_IS_REPLY) { | 78 | if ((ctinfo) < IP_CT_IS_REPLY) { |
81 | mangle_sip_packet(pskb, ctinfo, ct, dptr, | 79 | mangle_sip_packet(pskb, ctinfo, ct, dptr, |
82 | (*pskb)->len - dataoff, | 80 | (*pskb)->len - dataoff, |
83 | buffer, bufflen, | 81 | buffer, bufflen, POS_CONTACT); |
84 | &ct_sip_hdrs[POS_CONTACT]); | ||
85 | return 1; | 82 | return 1; |
86 | } | 83 | } |
87 | 84 | ||
88 | if (!mangle_sip_packet(pskb, ctinfo, ct, dptr, | 85 | if (!mangle_sip_packet(pskb, ctinfo, ct, dptr, |
89 | (*pskb)->len - dataoff, | 86 | (*pskb)->len - dataoff, |
90 | buffer, bufflen, &ct_sip_hdrs[POS_VIA])) | 87 | buffer, bufflen, POS_VIA)) |
91 | return 0; | 88 | return 0; |
92 | 89 | ||
93 | /* This search should ignore case, but later.. */ | 90 | /* This search should ignore case, but later.. */ |
@@ -102,25 +99,24 @@ static unsigned int ip_nat_sip(struct sk_buff **pskb, | |||
102 | 99 | ||
103 | return mangle_sip_packet(pskb, ctinfo, ct, dptr, | 100 | return mangle_sip_packet(pskb, ctinfo, ct, dptr, |
104 | (*pskb)->len - dataoff, | 101 | (*pskb)->len - dataoff, |
105 | buffer, bufflen, | 102 | buffer, bufflen, POS_CONTACT); |
106 | &ct_sip_hdrs[POS_CONTACT]); | ||
107 | } | 103 | } |
108 | if ((ctinfo) < IP_CT_IS_REPLY) { | 104 | if ((ctinfo) < IP_CT_IS_REPLY) { |
109 | if (!mangle_sip_packet(pskb, ctinfo, ct, dptr, | 105 | if (!mangle_sip_packet(pskb, ctinfo, ct, dptr, |
110 | (*pskb)->len - dataoff, | 106 | (*pskb)->len - dataoff, |
111 | buffer, bufflen, &ct_sip_hdrs[POS_VIA])) | 107 | buffer, bufflen, POS_VIA)) |
112 | return 0; | 108 | return 0; |
113 | 109 | ||
114 | /* Mangle Contact if exists only. - watch udp_nat_mangle()! */ | 110 | /* Mangle Contact if exists only. - watch udp_nat_mangle()! */ |
115 | mangle_sip_packet(pskb, ctinfo, ct, dptr, (*pskb)->len - dataoff, | 111 | mangle_sip_packet(pskb, ctinfo, ct, dptr, (*pskb)->len - dataoff, |
116 | buffer, bufflen, &ct_sip_hdrs[POS_CONTACT]); | 112 | buffer, bufflen, POS_CONTACT); |
117 | return 1; | 113 | return 1; |
118 | } | 114 | } |
119 | /* This mangle requests headers. */ | 115 | /* This mangle requests headers. */ |
120 | return mangle_sip_packet(pskb, ctinfo, ct, dptr, | 116 | return mangle_sip_packet(pskb, ctinfo, ct, dptr, |
121 | ct_sip_lnlen(*dptr, | 117 | ct_sip_lnlen(*dptr, |
122 | *dptr + (*pskb)->len - dataoff), | 118 | *dptr + (*pskb)->len - dataoff), |
123 | buffer, bufflen, &ct_sip_hdrs[POS_REQ_HEADER]); | 119 | buffer, bufflen, POS_REQ_HEADER); |
124 | } | 120 | } |
125 | 121 | ||
126 | static int mangle_content_len(struct sk_buff **pskb, | 122 | static int mangle_content_len(struct sk_buff **pskb, |
@@ -136,7 +132,7 @@ static int mangle_content_len(struct sk_buff **pskb, | |||
136 | 132 | ||
137 | /* Get actual SDP lenght */ | 133 | /* Get actual SDP lenght */ |
138 | if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff, | 134 | if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff, |
139 | &matchlen, &ct_sip_hdrs[POS_SDP_HEADER]) > 0) { | 135 | &matchlen, POS_SDP_HEADER) > 0) { |
140 | 136 | ||
141 | /* since ct_sip_get_info() give us a pointer passing 'v=' | 137 | /* since ct_sip_get_info() give us a pointer passing 'v=' |
142 | we need to add 2 bytes in this count. */ | 138 | we need to add 2 bytes in this count. */ |
@@ -144,7 +140,7 @@ static int mangle_content_len(struct sk_buff **pskb, | |||
144 | 140 | ||
145 | /* Now, update SDP lenght */ | 141 | /* Now, update SDP lenght */ |
146 | if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff, | 142 | if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff, |
147 | &matchlen, &ct_sip_hdrs[POS_CONTENT]) > 0) { | 143 | &matchlen, POS_CONTENT) > 0) { |
148 | 144 | ||
149 | bufflen = sprintf(buffer, "%u", c_len); | 145 | bufflen = sprintf(buffer, "%u", c_len); |
150 | 146 | ||
@@ -170,17 +166,17 @@ static unsigned int mangle_sdp(struct sk_buff **pskb, | |||
170 | /* Mangle owner and contact info. */ | 166 | /* Mangle owner and contact info. */ |
171 | bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip)); | 167 | bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip)); |
172 | if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, | 168 | if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, |
173 | buffer, bufflen, &ct_sip_hdrs[POS_OWNER])) | 169 | buffer, bufflen, POS_OWNER)) |
174 | return 0; | 170 | return 0; |
175 | 171 | ||
176 | if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, | 172 | if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, |
177 | buffer, bufflen, &ct_sip_hdrs[POS_CONNECTION])) | 173 | buffer, bufflen, POS_CONNECTION)) |
178 | return 0; | 174 | return 0; |
179 | 175 | ||
180 | /* Mangle media port. */ | 176 | /* Mangle media port. */ |
181 | bufflen = sprintf(buffer, "%u", port); | 177 | bufflen = sprintf(buffer, "%u", port); |
182 | if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, | 178 | if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, |
183 | buffer, bufflen, &ct_sip_hdrs[POS_MEDIA])) | 179 | buffer, bufflen, POS_MEDIA)) |
184 | return 0; | 180 | return 0; |
185 | 181 | ||
186 | return mangle_content_len(pskb, ctinfo, ct, dptr); | 182 | return mangle_content_len(pskb, ctinfo, ct, dptr); |