Skip to contentSkip to conversation

[PATCH 4/7 parse attributes with nfattr_parse in nfnetlink_check_attribute

PATCH Pablo Neira Ayuso 3 participants 5 messages Feb 12, 2007 – Mar 14, 2007

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

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.

Signature · 2 lines
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

[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.

net/netfilter/nfnetlink.c +2 -14
Index: net-2.6.git/net/netfilter/nfnetlink.c
===================================================================
@@ -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
#1 lore raw
Quoted 6 lines · Pablo Neira Ayuso

[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?

Quoted 36 lines

Index: net-2.6.git/net/netfilter/nfnetlink.c
===================================================================

net/netfilter/nfnetlink.c +2 -14
@@ -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
#2 lore raw

* Patrick McHardy <[email protected]> 2007-02-13 12:05

Quoted 14 lines
Quoted 6 lines · Pablo Neira Ayuso

[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.

Quoted 4 lines

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.

author maintainer
#3 lore raw
Quoted 8 lines · Thomas Graf

* Patrick McHardy <[email protected]> 2007-02-13 12:05

Quoted 7 lines

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.

Quoted 8 lines
Quoted 4 lines

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 ;)

Signature · 2 lines
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
#4 lore raw
Quoted 4 lines · Pablo Neira Ayuso
Quoted 2 lines · Thomas Graf

* Patrick McHardy <[email protected]> 2007-02-13 12:05 ´

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

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.