All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute
@ 2007-02-12 22:46 Pablo Neira Ayuso
  2007-02-13 11:05 ` Patrick McHardy
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2007-02-12 22:46 UTC (permalink / raw)
  To: Netfilter Development Mailinglist; +Cc: Patrick McHardy

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Use nfattr_parse to parse attributes, this patch also modifies the
default behaviour since unknown attributes will be ignored instead of
returning EINVAL. This ensure backward compatibility: new libraries with
new attributes and old kernels can work.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-- 
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris

[-- Attachment #2: 05.patch --]
[-- Type: text/plain, Size: 1588 bytes --]

[PATCH] parse attributes with nfattr_parse in nfnetlink_check_attribute

Use nfattr_parse to parse attributes, this patch also modifies the default 
behaviour since unknown attributes will be ignored instead of returning 
EINVAL. This ensure backward compatibility: new libraries with new 
attributes and old kernels can work.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Index: net-2.6.git/net/netfilter/nfnetlink.c
===================================================================
--- net-2.6.git.orig/net/netfilter/nfnetlink.c	2007-01-19 19:37:01.000000000 +0100
+++ net-2.6.git/net/netfilter/nfnetlink.c	2007-01-19 19:48:18.000000000 +0100
@@ -128,26 +128,14 @@ nfnetlink_check_attributes(struct nfnetl
 			   struct nlmsghdr *nlh, struct nfattr *cda[])
 {
 	int min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
-	u_int16_t attr_count;
 	u_int8_t cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type);
-
-	attr_count = subsys->cb[cb_id].attr_count;
-	memset(cda, 0, sizeof(struct nfattr *) * attr_count);
+	u_int16_t attr_count = subsys->cb[cb_id].attr_count;
 
 	/* check attribute lengths. */
 	if (likely(nlh->nlmsg_len > min_len)) {
 		struct nfattr *attr = NFM_NFA(NLMSG_DATA(nlh));
 		int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
-
-		while (NFA_OK(attr, attrlen)) {
-			unsigned flavor = NFA_TYPE(attr);
-			if (flavor) {
-				if (flavor > attr_count)
-					return -EINVAL;
-				cda[flavor - 1] = attr;
-			}
-			attr = NFA_NEXT(attr, attrlen);
-		}
+		nfattr_parse(cda, attr_count, attr, attrlen);
 	}
 
 	/* implicit: if nlmsg_len == min_len, we return 0, and an empty

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute
  2007-02-12 22:46 [PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute Pablo Neira Ayuso
@ 2007-02-13 11:05 ` Patrick McHardy
  2007-03-06 21:45   ` Thomas Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Patrick McHardy @ 2007-02-13 11:05 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Netfilter Development Mailinglist

Pablo Neira Ayuso wrote:
> [PATCH] parse attributes with nfattr_parse in nfnetlink_check_attribute
> 
> Use nfattr_parse to parse attributes, this patch also modifies the default 
> behaviour since unknown attributes will be ignored instead of returning 
> EINVAL. This ensure backward compatibility: new libraries with new 
> attributes and old kernels can work.

Currently other netlink subsystems return errors for the first level
of attributes and accept unknown attributes on deeper levels. I'm
not sure which I prefer, ignoring unknown attributes makes it
impossible for userspace to know that something isn't going to have
any effect, returning an error makes it harder to support new features.

I know Thomas had intentions of increasing consistency in this area,
I'm just not sure in which direction :)

Thomas, what do you think of this patch?

> 
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> 
> Index: net-2.6.git/net/netfilter/nfnetlink.c
> ===================================================================
> --- net-2.6.git.orig/net/netfilter/nfnetlink.c	2007-01-19 19:37:01.000000000 +0100
> +++ net-2.6.git/net/netfilter/nfnetlink.c	2007-01-19 19:48:18.000000000 +0100
> @@ -128,26 +128,14 @@ nfnetlink_check_attributes(struct nfnetl
>  			   struct nlmsghdr *nlh, struct nfattr *cda[])
>  {
>  	int min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
> -	u_int16_t attr_count;
>  	u_int8_t cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type);
> -
> -	attr_count = subsys->cb[cb_id].attr_count;
> -	memset(cda, 0, sizeof(struct nfattr *) * attr_count);
> +	u_int16_t attr_count = subsys->cb[cb_id].attr_count;
>  
>  	/* check attribute lengths. */
>  	if (likely(nlh->nlmsg_len > min_len)) {
>  		struct nfattr *attr = NFM_NFA(NLMSG_DATA(nlh));
>  		int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
> -
> -		while (NFA_OK(attr, attrlen)) {
> -			unsigned flavor = NFA_TYPE(attr);
> -			if (flavor) {
> -				if (flavor > attr_count)
> -					return -EINVAL;
> -				cda[flavor - 1] = attr;
> -			}
> -			attr = NFA_NEXT(attr, attrlen);
> -		}
> +		nfattr_parse(cda, attr_count, attr, attrlen);
>  	}
>  
>  	/* implicit: if nlmsg_len == min_len, we return 0, and an empty

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute
  2007-02-13 11:05 ` Patrick McHardy
@ 2007-03-06 21:45   ` Thomas Graf
  2007-03-07 10:43     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Graf @ 2007-03-06 21:45 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: Netfilter Development Mailinglist, Pablo Neira Ayuso

* Patrick McHardy <kaber@trash.net> 2007-02-13 12:05
> Pablo Neira Ayuso wrote:
> > [PATCH] parse attributes with nfattr_parse in nfnetlink_check_attribute
> > 
> > Use nfattr_parse to parse attributes, this patch also modifies the default 
> > behaviour since unknown attributes will be ignored instead of returning 
> > EINVAL. This ensure backward compatibility: new libraries with new 
> > attributes and old kernels can work.
> 
> Currently other netlink subsystems return errors for the first level
> of attributes and accept unknown attributes on deeper levels. I'm
> not sure which I prefer, ignoring unknown attributes makes it
> impossible for userspace to know that something isn't going to have
> any effect, returning an error makes it harder to support new features.
> 
> I know Thomas had intentions of increasing consistency in this area,
> I'm just not sure in which direction :)
> 
> Thomas, what do you think of this patch?

I believe that all unknown attributes should be ignored so recent
userspace code can function on older kernels. That's the way I'm
working towards.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute
  2007-03-06 21:45   ` Thomas Graf
@ 2007-03-07 10:43     ` Pablo Neira Ayuso
  2007-03-14  8:23       ` Patrick McHardy
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2007-03-07 10:43 UTC (permalink / raw)
  To: Thomas Graf; +Cc: Netfilter Development Mailinglist, Patrick McHardy

Thomas Graf wrote:
> * Patrick McHardy <kaber@trash.net> 2007-02-13 12:05
>> Pablo Neira Ayuso wrote:
>> Currently other netlink subsystems return errors for the first level
>> of attributes and accept unknown attributes on deeper levels. I'm
>> not sure which I prefer, ignoring unknown attributes makes it
>> impossible for userspace to know that something isn't going to have
>> any effect, returning an error makes it harder to support new features.
>>
>> I know Thomas had intentions of increasing consistency in this area,
>> I'm just not sure in which direction :)
>>
>> Thomas, what do you think of this patch?
> 
> I believe that all unknown attributes should be ignored so recent
> userspace code can function on older kernels. That's the way I'm
> working towards.

Then I'll resend the patch if nobody objects anymore ;)

-- 
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute
  2007-03-07 10:43     ` Pablo Neira Ayuso
@ 2007-03-14  8:23       ` Patrick McHardy
  0 siblings, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2007-03-14  8:23 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Netfilter Development Mailinglist

Pablo Neira Ayuso wrote:
> Thomas Graf wrote:
> 
>>* Patrick McHardy <kaber@trash.net> 2007-02-13 12:05
>>´
>>>Thomas, what do you think of this patch?
>>
>>I believe that all unknown attributes should be ignored so recent
>>userspace code can function on older kernels. That's the way I'm
>>working towards.
> 
> 
> Then I'll resend the patch if nobody objects anymore ;)


Don't bother, I've applied the patch you sent. Thanks everybody.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-03-14  8:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-12 22:46 [PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute Pablo Neira Ayuso
2007-02-13 11:05 ` Patrick McHardy
2007-03-06 21:45   ` Thomas Graf
2007-03-07 10:43     ` Pablo Neira Ayuso
2007-03-14  8:23       ` Patrick McHardy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.