diff mbox

[rfc,02/13,RFC,02/13] netfilter: nf_conntrack_sip: Add callid parser

Message ID 20100805115239.880722744@vergenet.net
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Simon Horman Aug. 5, 2010, 11:47 a.m. UTC
Signed-off-by: Simon Horman <horms@verge.net.au>
---
 include/linux/netfilter/nf_conntrack_sip.h |    1 +
 net/netfilter/nf_conntrack_sip.c           |   39 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

Comments

Patrick McHardy Aug. 6, 2010, 2 p.m. UTC | #1
Am 05.08.2010 13:47, schrieb Simon Horman:
> diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
> index 2fd1ea2..715ce54 100644
> --- a/net/netfilter/nf_conntrack_sip.c
> +++ b/net/netfilter/nf_conntrack_sip.c
> @@ -130,6 +130,44 @@ static int digits_len(const struct nf_conn *ct, const char *dptr,
>  	return len;
>  }
>  
> +static int iswordc(const char c)
> +{
> +	if (isalnum(c) || c == '!' || c == '"' || c == '%' ||
> +	    (c >= '(' && c <= '/') || c == ':' || c == '<' || c == '>' ||
> +	    c == '?' || (c >= '[' && c <= ']') || c == '_' || c == '`' ||
> +	    c == '{' || c == '}' || c == '~')
> +		return 1;
> +	return 0;
> +}
> +
> +static int word_len(const char *dptr, const char *limit)
> +{
> +	int len = 0;
> +	while (dptr < limit && iswordc(*dptr)) {
> +		dptr++;
> +		len++;
> +	}
> +	return len;
> +}

Since the Call-ID can't contain whitespace, couldn't we simply
determine the length by looking for the next newline or whitespace
character?
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Simon Horman Aug. 6, 2010, 2:31 p.m. UTC | #2
On Fri, Aug 06, 2010 at 04:00:49PM +0200, Patrick McHardy wrote:
> Am 05.08.2010 13:47, schrieb Simon Horman:
> > diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
> > index 2fd1ea2..715ce54 100644
> > --- a/net/netfilter/nf_conntrack_sip.c
> > +++ b/net/netfilter/nf_conntrack_sip.c
> > @@ -130,6 +130,44 @@ static int digits_len(const struct nf_conn *ct, const char *dptr,
> >  	return len;
> >  }
> >  
> > +static int iswordc(const char c)
> > +{
> > +	if (isalnum(c) || c == '!' || c == '"' || c == '%' ||
> > +	    (c >= '(' && c <= '/') || c == ':' || c == '<' || c == '>' ||
> > +	    c == '?' || (c >= '[' && c <= ']') || c == '_' || c == '`' ||
> > +	    c == '{' || c == '}' || c == '~')
> > +		return 1;
> > +	return 0;
> > +}
> > +
> > +static int word_len(const char *dptr, const char *limit)
> > +{
> > +	int len = 0;
> > +	while (dptr < limit && iswordc(*dptr)) {
> > +		dptr++;
> > +		len++;
> > +	}
> > +	return len;
> > +}
> 
> Since the Call-ID can't contain whitespace, couldn't we simply
> determine the length by looking for the next newline or whitespace
> character?

Well, there are other characters (e.g. '#') it can't contain - unless I
read the RFC incorrectly.  Are you concerned about speed, code complexity,
or something else?

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/netfilter/nf_conntrack_sip.h b/include/linux/netfilter/nf_conntrack_sip.h
index ff8cfbc..0ce91d5 100644
--- a/include/linux/netfilter/nf_conntrack_sip.h
+++ b/include/linux/netfilter/nf_conntrack_sip.h
@@ -89,6 +89,7 @@  enum sip_header_types {
 	SIP_HDR_VIA_TCP,
 	SIP_HDR_EXPIRES,
 	SIP_HDR_CONTENT_LENGTH,
+	SIP_HDR_CALL_ID,
 };
 
 enum sdp_header_types {
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
index 2fd1ea2..715ce54 100644
--- a/net/netfilter/nf_conntrack_sip.c
+++ b/net/netfilter/nf_conntrack_sip.c
@@ -130,6 +130,44 @@  static int digits_len(const struct nf_conn *ct, const char *dptr,
 	return len;
 }
 
+static int iswordc(const char c)
+{
+	if (isalnum(c) || c == '!' || c == '"' || c == '%' ||
+	    (c >= '(' && c <= '/') || c == ':' || c == '<' || c == '>' ||
+	    c == '?' || (c >= '[' && c <= ']') || c == '_' || c == '`' ||
+	    c == '{' || c == '}' || c == '~')
+		return 1;
+	return 0;
+}
+
+static int word_len(const char *dptr, const char *limit)
+{
+	int len = 0;
+	while (dptr < limit && iswordc(*dptr)) {
+		dptr++;
+		len++;
+	}
+	return len;
+}
+
+static int callid_len(const struct nf_conn *ct, const char *dptr,
+		      const char *limit, int *shift)
+{
+	int len, domain_len;
+
+	len = word_len(dptr, limit);
+	dptr += len;
+	if (!len || dptr == limit || *dptr != '@')
+		return len;
+	dptr++;
+	len++;
+
+	domain_len = word_len(dptr, limit);
+	if (!domain_len)
+		return 0;
+	return len + domain_len;
+}
+
 /* get media type + port length */
 static int media_len(const struct nf_conn *ct, const char *dptr,
 		     const char *limit, int *shift)
@@ -299,6 +337,7 @@  static const struct sip_header ct_sip_hdrs[] = {
 	[SIP_HDR_VIA_TCP]		= SIP_HDR("Via", "v", "TCP ", epaddr_len),
 	[SIP_HDR_EXPIRES]		= SIP_HDR("Expires", NULL, NULL, digits_len),
 	[SIP_HDR_CONTENT_LENGTH]	= SIP_HDR("Content-Length", "l", NULL, digits_len),
+	[SIP_HDR_CALL_ID]		= SIP_HDR("Call-Id", "i", NULL, callid_len),
 };
 
 static const char *sip_follow_continuation(const char *dptr, const char *limit)