Skip to content

Commit ea45f12

Browse files
kaberdavem330
authored andcommitted
[NETFILTER]: nf_conntrack_sip: parse SIP headers properly
Introduce new function for SIP header parsing that properly deals with continuation lines and whitespace in headers and use it. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ac36774 commit ea45f12

File tree

3 files changed

+151
-168
lines changed

3 files changed

+151
-168
lines changed

include/linux/netfilter/nf_conntrack_sip.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55
#define SIP_PORT 5060
66
#define SIP_TIMEOUT 3600
77

8-
enum sip_header_pos {
9-
POS_FROM,
10-
POS_TO,
11-
POS_VIA,
12-
POS_CONTACT,
13-
POS_CONTENT,
14-
};
15-
168
struct sip_header {
179
const char *name;
1810
const char *cname;
@@ -36,9 +28,20 @@ struct sip_header {
3628
.match_len = (__match), \
3729
}
3830

31+
#define SIP_HDR(__name, __cname, __search, __match) \
32+
__SIP_HDR(__name, __cname, __search, __match)
33+
3934
#define SDP_HDR(__name, __search, __match) \
4035
__SIP_HDR(__name, NULL, __search, __match)
4136

37+
enum sip_header_types {
38+
SIP_HDR_FROM,
39+
SIP_HDR_TO,
40+
SIP_HDR_CONTACT,
41+
SIP_HDR_VIA,
42+
SIP_HDR_CONTENT_LENGTH,
43+
};
44+
4245
enum sdp_header_types {
4346
SDP_HDR_UNSPEC,
4447
SDP_HDR_VERSION,
@@ -60,13 +63,10 @@ extern unsigned int (*nf_nat_sdp_hook)(struct sk_buff *skb,
6063
extern int ct_sip_parse_request(const struct nf_conn *ct,
6164
const char *dptr, unsigned int datalen,
6265
unsigned int *matchoff, unsigned int *matchlen);
63-
extern int ct_sip_get_info(const struct nf_conn *ct, const char *dptr,
64-
size_t dlen, unsigned int *matchoff,
65-
unsigned int *matchlen, enum sip_header_pos pos);
66-
extern int ct_sip_lnlen(const char *line, const char *limit);
67-
extern const char *ct_sip_search(const char *needle, const char *haystack,
68-
size_t needle_len, size_t haystack_len,
69-
int case_sensitive);
66+
extern int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
67+
unsigned int dataoff, unsigned int datalen,
68+
enum sip_header_types type,
69+
unsigned int *matchoff, unsigned int *matchlen);
7070

7171
extern int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr,
7272
unsigned int dataoff, unsigned int datalen,

net/ipv4/netfilter/nf_nat_sip.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ static int map_addr(struct sk_buff *skb,
108108

109109
static int map_sip_addr(struct sk_buff *skb,
110110
const char **dptr, unsigned int *datalen,
111-
enum sip_header_pos pos, struct addr_map *map)
111+
enum sip_header_types type, struct addr_map *map)
112112
{
113113
enum ip_conntrack_info ctinfo;
114114
struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
115115
unsigned int matchlen, matchoff;
116116

117-
if (ct_sip_get_info(ct, *dptr, *datalen, &matchoff, &matchlen,
118-
pos) <= 0)
117+
if (ct_sip_get_header(ct, *dptr, 0, *datalen, type,
118+
&matchoff, &matchlen) <= 0)
119119
return 1;
120120
return map_addr(skb, dptr, datalen, matchoff, matchlen, map);
121121
}
@@ -141,10 +141,10 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
141141
return NF_DROP;
142142
}
143143

144-
if (!map_sip_addr(skb, dptr, datalen, POS_FROM, &map) ||
145-
!map_sip_addr(skb, dptr, datalen, POS_TO, &map) ||
146-
!map_sip_addr(skb, dptr, datalen, POS_VIA, &map) ||
147-
!map_sip_addr(skb, dptr, datalen, POS_CONTACT, &map))
144+
if (!map_sip_addr(skb, dptr, datalen, SIP_HDR_FROM, &map) ||
145+
!map_sip_addr(skb, dptr, datalen, SIP_HDR_TO, &map) ||
146+
!map_sip_addr(skb, dptr, datalen, SIP_HDR_VIA, &map) ||
147+
!map_sip_addr(skb, dptr, datalen, SIP_HDR_CONTACT, &map))
148148
return NF_DROP;
149149
return NF_ACCEPT;
150150
}
@@ -166,8 +166,8 @@ static int mangle_content_len(struct sk_buff *skb,
166166
c_len = *datalen - matchoff + strlen("v=");
167167

168168
/* Now, update SDP length */
169-
if (ct_sip_get_info(ct, *dptr, *datalen, &matchoff, &matchlen,
170-
POS_CONTENT) <= 0)
169+
if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_CONTENT_LENGTH,
170+
&matchoff, &matchlen) <= 0)
171171
return 0;
172172

173173
buflen = sprintf(buffer, "%u", c_len);

0 commit comments

Comments
 (0)