bridge: modify bridge af spec parser to accomodate vlan list and ranges
Subsystems (3)
PATCH v2 2/2 bridge: modify bridge af spec parser to accomodate vlan list and ranges
From: Roopa Prabhu <[email protected]>
This patch modifies br_afspec to parse incoming IFLA_BRIDGE_VLAN_INFO_LIST
--- net/bridge/br_netlink.c | 115 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 30 deletions(-)
net/bridge/br_netlink.c +85 -30
@@ -226,53 +226,108 @@ static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { [IFLA_BRIDGE_VLAN_INFO_LIST] = { .type = NLA_NESTED, }, }; +static int br_vlan_info (struct net_bridge *br,struct net_bridge_port *p, +int cmd,struct bridge_vlan_info *vinfo) +{ +int err =0 ; + +switch (cmd) { +case RTM_SETLINK : +if (p) { + err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); +if (err) +break ; + +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) + err =br_vlan_add (p->br, vinfo->vid, + vinfo->flags); + }else { + err =br_vlan_add (br, vinfo->vid, vinfo->flags); + } +break ; + +case RTM_DELLINK : +if (p) { +nbp_vlan_delete (p, vinfo->vid); +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) +br_vlan_delete (p->br, vinfo->vid); + }else { +br_vlan_delete (br, vinfo->vid); + } +break ; + } + +return err; +} +static int br_afspec (struct net_bridge *br,struct net_bridge_port *p,struct nlattr *af_spec,int cmd) {struct nlattr *tb[IFLA_BRIDGE_MAX +1 ]; +struct nlattr *attr;int err =0 ; +int rem; err =nla_parse_nested (tb,IFLA_BRIDGE_MAX , af_spec, ifla_br_policy);if (err)return err;if (tb[IFLA_BRIDGE_VLAN_INFO ]) { -struct bridge_vlan_info *vinfo; - - vinfo =nla_data (tb[IFLA_BRIDGE_VLAN_INFO ]); - -if (!vinfo->vid || vinfo->vid >=VLAN_VID_MASK ) -return -EINVAL ; - -switch (cmd) { -case RTM_SETLINK : -if (p) { - err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); -if (err) -break ; - -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) - err =br_vlan_add (p->br, vinfo->vid, - vinfo->flags); - }else - err =br_vlan_add (br, vinfo->vid, vinfo->flags); - -break ; - -case RTM_DELLINK : -if (p) { -nbp_vlan_delete (p, vinfo->vid); -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) -br_vlan_delete (p->br, vinfo->vid); - }else -br_vlan_delete (br, vinfo->vid); -break ; + attr = tb[IFLA_BRIDGE_VLAN_INFO ]; +if (nla_len (attr) !=sizeof (struct bridge_vlan_info )) + goto err_inval; + + err =br_vlan_info (br, p, cmd, + (struct bridge_vlan_info *)nla_data (attr)); + + }else if (tb[IFLA_BRIDGE_VLAN_INFO_LIST ]) { +struct bridge_vlan_info *vinfo_start =NULL ; +struct bridge_vlan_info *vinfo =NULL ; + +nla_for_each_nested (attr, tb[IFLA_BRIDGE_VLAN_INFO_LIST ], rem) { +if (nla_len (attr) !=sizeof (struct bridge_vlan_info ) || +nla_type (attr) !=IFLA_BRIDGE_VLAN_INFO ) + goto err_inval; + vinfo =nla_data (attr); +if (vinfo->flags &BRIDGE_VLAN_INFO_RANGE_START ) { +if (vinfo_start) + goto err_inval; + vinfo_start = vinfo; +continue ; + } + +if (vinfo_start) { +int v; + +if (!(vinfo->flags &BRIDGE_VLAN_INFO_RANGE_END )) + goto err_inval; + +if (vinfo->vid < vinfo_start->vid) + goto err_inval; + +for (v = vinfo_start->vid; v <= vinfo->vid; + v++) { + vinfo_start->vid = v; + err =br_vlan_info (br, p, cmd, + vinfo_start); +if (err) +break ; + } + vinfo_start =NULL ; + }else { + err =br_vlan_info (br, p, cmd, vinfo); + } +if (err) +break ; } }return err; + +err_inval: +return -EINVAL ; }static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX +1 ] = {
Signature · 1 line
1.7.10.4
Quoted 129 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Wednesday, December 31, 2014 6:49 PM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Roopa Prabhu
Subject: [PATCH net-next v2 2/2] bridge: modify bridge af spec parser to accomodate vlan list and rangesFrom: Roopa Prabhu <[email protected]>
This patch modifies
br_afspecto parse incomingIFLA_BRIDGE_VLAN_INFO_LISTSigned-off-by Roopa Prabhu <[email protected]>---
net/bridge/br_netlink.c| 115 ++++++++++++++++++++++++++++++++++------------ -1 file changed, 85 insertions(+), 30 deletions(-)net/bridge/br_netlink.c +56
-30@@ -226,53 +226,108 @@ static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { [IFLA_BRIDGE_VLAN_INFO_LIST] = { .type = NLA_NESTED, }, }; +static int br_vlan_info (struct net_bridge *br,struct net_bridge_port *p, +int cmd,struct bridge_vlan_info *vinfo) +{ +int err =0 ; + +switch (cmd) { +case RTM_SETLINK : +if (p) { + err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); +if (err) +break ; + +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) + err =br_vlan_add (p->br, vinfo->vid, + vinfo->flags); + }else { + err =br_vlan_add (br, vinfo->vid, vinfo->flags); + } +break ; + +case RTM_DELLINK : +if (p) { +nbp_vlan_delete (p, vinfo->vid); +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) +br_vlan_delete (p->br, vinfo->vid); + }else { +br_vlan_delete (br, vinfo->vid); + } +break ; + } + +return err; +} +static int br_afspec (struct net_bridge *br,struct net_bridge_port *p,struct nlattr *af_spec,int cmd) {struct nlattr *tb[IFLA_BRIDGE_MAX +1 ]; +struct nlattr *attr;int err =0 ; +int rem; err =nla_parse_nested (tb,IFLA_BRIDGE_MAX , af_spec, ifla_br_policy);if (err)return err;if (tb[IFLA_BRIDGE_VLAN_INFO ]) { -struct bridge_vlan_info *vinfo; - - vinfo =nla_data (tb[IFLA_BRIDGE_VLAN_INFO ]); - -if (!vinfo->vid || vinfo->vid >=VLAN_VID_MASK ) -return -EINVAL ; - -switch (cmd) { -case RTM_SETLINK : -if (p) { - err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); -if (err) -break ; - -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) - err =br_vlan_add (p->br, vinfo->vid, - vinfo->flags); - }else - err =br_vlan_add (br, vinfo->vid, vinfo->flags); - -break ; - -case RTM_DELLINK : -if (p) { -nbp_vlan_delete (p, vinfo->vid); -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) -br_vlan_delete (p->br, vinfo->vid); - }else -br_vlan_delete (br, vinfo->vid); -break ; + attr = tb[IFLA_BRIDGE_VLAN_INFO ]; +if (nla_len (attr) !=sizeof (struct bridge_vlan_info )) + goto err_inval; + + err =br_vlan_info (br, p, cmd, + (struct bridge_vlan_info *)nla_data (attr)); + + }else if (tb[IFLA_BRIDGE_VLAN_INFO_LIST ]) { +struct bridge_vlan_info *vinfo_start =NULL ; +struct bridge_vlan_info *vinfo =NULL ; + +nla_for_each_nested (attr, tb[IFLA_BRIDGE_VLAN_INFO_LIST ], rem) { +if (nla_len (attr) !=sizeof (struct bridge_vlan_info ) || +nla_type (attr) !=IFLA_BRIDGE_VLAN_INFO ) + goto err_inval; + vinfo =nla_data (attr); +if (vinfo->flags &BRIDGE_VLAN_INFO_RANGE_START ) { +if (vinfo_start) + goto err_inval; + vinfo_start = vinfo;
net/bridge/br_netlink.c static const struct nla_policy · line 308
Quoted 10 lines
net/bridge/br_netlink.c +10
-0+continue ; + } + +if (vinfo_start) { +int v; + +if (!(vinfo->flags &BRIDGE_VLAN_INFO_RANGE_END )) + goto err_inval; + +if (vinfo->vid < vinfo_start->vid)
This check rejects inverted range. However it allows the RANGE_START and RANGE_END vinfos to have the same vid. Isn't it inconsistent with the rejection of a single vinfo with both RANGE_START and RANGE_END set?
net/bridge/br_netlink.c static const struct nla_policy · line 309
Quoted 1 line
net/bridge/br_netlink.c +1
-0+ goto err_inval;
Are additional validation such as consistency of flags between the RANGE_START and RANGE_END vinfos is needed here?
The loop below applies flags (more precisely all data except for vid) from the RANGE_START vinfo to all vids in the range. All data from the RANGE_END vinfo is ignored.
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 312
Quoted 4 lines
net/bridge/br_netlink.c +4
-0+ +for (v = vinfo_start->vid; v <= vinfo->vid; + v++) { + vinfo_start->vid = v;
This changes the vinfo with RANGE_START flag within the incoming message. Would it be better to left the input message unmodified and use a local copy of struct bridge_vlan_info?
Quoted 28 lines
net/bridge/br_netlink.c +14
-0+ err =br_vlan_info (br, p, cmd, + vinfo_start); +if (err) +break ; + } + vinfo_start =NULL ; + }else { + err =br_vlan_info (br, p, cmd, vinfo); + } +if (err) +break ; } }return err; + +err_inval: +return -EINVAL ; }static const struct
nla_policybr_port_policy[IFLA_BRPORT_MAX + 1] = { --
1.7.10.4--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 133 lines · Ronen
Quoted 133 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Wednesday, December 31, 2014 6:49 PM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Roopa Prabhu
Subject: [PATCH net-next v2 2/2] bridge: modify bridge af spec parser to accomodate vlan list and rangesFrom: Roopa Prabhu <[email protected]>
This patch modifies
br_afspecto parse incomingIFLA_BRIDGE_VLAN_INFO_LISTSigned-off-by Roopa Prabhu <[email protected]>---
net/bridge/br_netlink.c| 115 ++++++++++++++++++++++++++++++++++------------ -1 file changed, 85 insertions(+), 30 deletions(-)net/bridge/br_netlink.c +61
-30@@ -226,53 +226,108 @@ static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { [IFLA_BRIDGE_VLAN_INFO_LIST] = { .type = NLA_NESTED, }, }; +static int br_vlan_info (struct net_bridge *br,struct net_bridge_port *p, +int cmd,struct bridge_vlan_info *vinfo) +{ +int err =0 ; + +switch (cmd) { +case RTM_SETLINK : +if (p) { + err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); +if (err) +break ; + +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) + err =br_vlan_add (p->br, vinfo->vid, + vinfo->flags); + }else { + err =br_vlan_add (br, vinfo->vid, vinfo->flags); + } +break ; + +case RTM_DELLINK : +if (p) { +nbp_vlan_delete (p, vinfo->vid); +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) +br_vlan_delete (p->br, vinfo->vid); + }else { +br_vlan_delete (br, vinfo->vid); + } +break ; + } + +return err; +} +static int br_afspec (struct net_bridge *br,struct net_bridge_port *p,struct nlattr *af_spec,int cmd) {struct nlattr *tb[IFLA_BRIDGE_MAX +1 ]; +struct nlattr *attr;int err =0 ; +int rem; err =nla_parse_nested (tb,IFLA_BRIDGE_MAX , af_spec, ifla_br_policy);if (err)return err;if (tb[IFLA_BRIDGE_VLAN_INFO ]) { -struct bridge_vlan_info *vinfo; - - vinfo =nla_data (tb[IFLA_BRIDGE_VLAN_INFO ]); - -if (!vinfo->vid || vinfo->vid >=VLAN_VID_MASK ) -return -EINVAL ; - -switch (cmd) { -case RTM_SETLINK : -if (p) { - err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); -if (err) -break ; - -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) - err =br_vlan_add (p->br, vinfo->vid, - vinfo->flags); - }else - err =br_vlan_add (br, vinfo->vid, vinfo->flags); - -break ; - -case RTM_DELLINK : -if (p) { -nbp_vlan_delete (p, vinfo->vid); -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) -br_vlan_delete (p->br, vinfo->vid); - }else -br_vlan_delete (br, vinfo->vid); -break ; + attr = tb[IFLA_BRIDGE_VLAN_INFO ]; +if (nla_len (attr) !=sizeof (struct bridge_vlan_info )) + goto err_inval; + + err =br_vlan_info (br, p, cmd, + (struct bridge_vlan_info *)nla_data (attr)); + + }else if (tb[IFLA_BRIDGE_VLAN_INFO_LIST ]) { +struct bridge_vlan_info *vinfo_start =NULL ; +struct bridge_vlan_info *vinfo =NULL ; + +nla_for_each_nested (attr, tb[IFLA_BRIDGE_VLAN_INFO_LIST ], rem) { +if (nla_len (attr) !=sizeof (struct bridge_vlan_info ) || +nla_type (attr) !=IFLA_BRIDGE_VLAN_INFO ) + goto err_inval; + vinfo =nla_data (attr); +if (vinfo->flags &BRIDGE_VLAN_INFO_RANGE_START ) { +if (vinfo_start) + goto err_inval; + vinfo_start = vinfo; +continue ; + } + +if (vinfo_start) { +int v;
Quoted 8 lines
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 307
Quoted 5 lines
net/bridge/br_netlink.c +5
-0+ +if (!(vinfo->flags &BRIDGE_VLAN_INFO_RANGE_END )) + goto err_inval; + +if (vinfo->vid < vinfo_start->vid)This check rejects inverted range. However it allows the
RANGE_STARTandRANGE_ENDvinfos to have the same vid. Isn't it inconsistent with the rejection of a single vinfo with bothRANGE_STARTandRANGE_ENDset?
sure, i will make it <= to error out if they are equal.
Quoted 3 lines
net/bridge/br_netlink.c static const struct nla_policy · line 309
Quoted 1 line
net/bridge/br_netlink.c +1
-0+ goto err_inval;Are additional validation such as consistency of flags between the
RANGE_STARTandRANGE_ENDvinfos is needed here?
sure, i can add them (I have some of them in the iproute2 patch as well).
Quoted 11 lines
The loop below applies flags (more precisely all data except for vid) from the
RANGE_STARTvinfo to all vids in the range. All data from theRANGE_ENDvinfo is ignored.net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 312
Quoted 4 lines
net/bridge/br_netlink.c +4
-0+ +for (v = vinfo_start->vid; v <= vinfo->vid; + v++) { + vinfo_start->vid = v;This changes the vinfo with
RANGE_STARTflag within the incoming message. Would it be better to left the input message unmodified and use a local copy of structbridge_vlan_info?
agreed, I will make a copy.
Quoted 28 lines
Quoted 28 lines
net/bridge/br_netlink.c +14
-0+ err =br_vlan_info (br, p, cmd, + vinfo_start); +if (err) +break ; + } + vinfo_start =NULL ; + }else { + err =br_vlan_info (br, p, cmd, vinfo); + } +if (err) +break ; } }return err; + +err_inval: +return -EINVAL ; }static const struct
nla_policybr_port_policy[IFLA_BRPORT_MAX + 1] = { --
1.7.10.4--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 135 lines · Ronen
Quoted 135 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Wednesday, December 31, 2014 6:49 PM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Roopa Prabhu
Subject: [PATCH net-next v2 2/2] bridge: modify bridge af spec parser to accomodate vlan list and rangesFrom: Roopa Prabhu <[email protected]>
This patch modifies
br_afspecto parse incomingIFLA_BRIDGE_VLAN_INFO_LISTSigned-off-by Roopa Prabhu <[email protected]>---
net/bridge/br_netlink.c| 115 ++++++++++++++++++++++++++++++++++------------ -1 file changed, 85 insertions(+), 30 deletions(-)net/bridge/br_netlink.c +62
-30@@ -226,53 +226,108 @@ static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { [IFLA_BRIDGE_VLAN_INFO_LIST] = { .type = NLA_NESTED, }, }; +static int br_vlan_info (struct net_bridge *br,struct net_bridge_port *p, +int cmd,struct bridge_vlan_info *vinfo) +{ +int err =0 ; + +switch (cmd) { +case RTM_SETLINK : +if (p) { + err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); +if (err) +break ; + +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) + err =br_vlan_add (p->br, vinfo->vid, + vinfo->flags); + }else { + err =br_vlan_add (br, vinfo->vid, vinfo->flags); + } +break ; + +case RTM_DELLINK : +if (p) { +nbp_vlan_delete (p, vinfo->vid); +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) +br_vlan_delete (p->br, vinfo->vid); + }else { +br_vlan_delete (br, vinfo->vid); + } +break ; + } + +return err; +} +static int br_afspec (struct net_bridge *br,struct net_bridge_port *p,struct nlattr *af_spec,int cmd) {struct nlattr *tb[IFLA_BRIDGE_MAX +1 ]; +struct nlattr *attr;int err =0 ; +int rem; err =nla_parse_nested (tb,IFLA_BRIDGE_MAX , af_spec, ifla_br_policy);if (err)return err;if (tb[IFLA_BRIDGE_VLAN_INFO ]) { -struct bridge_vlan_info *vinfo; - - vinfo =nla_data (tb[IFLA_BRIDGE_VLAN_INFO ]); - -if (!vinfo->vid || vinfo->vid >=VLAN_VID_MASK ) -return -EINVAL ; - -switch (cmd) { -case RTM_SETLINK : -if (p) { - err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); -if (err) -break ; - -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) - err =br_vlan_add (p->br, vinfo->vid, - vinfo->flags); - }else - err =br_vlan_add (br, vinfo->vid, vinfo->flags); - -break ; - -case RTM_DELLINK : -if (p) { -nbp_vlan_delete (p, vinfo->vid); -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) -br_vlan_delete (p->br, vinfo->vid); - }else -br_vlan_delete (br, vinfo->vid); -break ; + attr = tb[IFLA_BRIDGE_VLAN_INFO ]; +if (nla_len (attr) !=sizeof (struct bridge_vlan_info )) + goto err_inval; + + err =br_vlan_info (br, p, cmd, + (struct bridge_vlan_info *)nla_data (attr)); + + }else if (tb[IFLA_BRIDGE_VLAN_INFO_LIST ]) { +struct bridge_vlan_info *vinfo_start =NULL ; +struct bridge_vlan_info *vinfo =NULL ; + +nla_for_each_nested (attr, tb[IFLA_BRIDGE_VLAN_INFO_LIST ], rem) { +if (nla_len (attr) !=sizeof (struct bridge_vlan_info ) || +nla_type (attr) !=IFLA_BRIDGE_VLAN_INFO ) + goto err_inval; + vinfo =nla_data (attr); +if (vinfo->flags &BRIDGE_VLAN_INFO_RANGE_START ) { +if (vinfo_start) + goto err_inval; + vinfo_start = vinfo; +continue ; + } + +if (vinfo_start) { +int v; +
Quoted 8 lines
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 307
Quoted 4 lines
net/bridge/br_netlink.c +4
-0+if (!(vinfo->flags &BRIDGE_VLAN_INFO_RANGE_END )) + goto err_inval; + +if (vinfo->vid < vinfo_start->vid)This check rejects inverted range. However it allows the
RANGE_STARTandRANGE_ENDvinfos to have the same vid. Isn't it inconsistent with the rejection of a single vinfo with bothRANGE_STARTandRANGE_ENDset?
Allowing both START and END to be set on single vinfo might simplify the encoding of LIST, so maybe it should be allowed.
Roopa, I know you dropped the subsequent notification patches from the set, but I suspect now with these new START/END markers, the notification algorithm can be very close to the original loop, without having to make copies of the vlan_bitmap and untagged_bitmap. Using both START/END on a single vinfo will keep the loop simple for adding single vids that are not in a range.
(hmmm...START/STOP or BEGIN/END? Seems START/END is mixing the two concepts...BEGIN/END seems best)
Quoted 142 lines · Scott Feldman
Quoted 133 lines · Ronen
Quoted 133 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Wednesday, December 31, 2014 6:49 PM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Roopa Prabhu
Subject: [PATCH net-next v2 2/2] bridge: modify bridge af spec parser to accomodate vlan list and rangesFrom: Roopa Prabhu <[email protected]>
This patch modifies
br_afspecto parse incomingIFLA_BRIDGE_VLAN_INFO_LISTSigned-off-by Roopa Prabhu <[email protected]>---
net/bridge/br_netlink.c| 115 ++++++++++++++++++++++++++++++++++------------ -1 file changed, 85 insertions(+), 30 deletions(-)net/bridge/br_netlink.c +61
-30@@ -226,53 +226,108 @@ static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { [IFLA_BRIDGE_VLAN_INFO_LIST] = { .type = NLA_NESTED, }, }; +static int br_vlan_info (struct net_bridge *br,struct net_bridge_port *p, +int cmd,struct bridge_vlan_info *vinfo) +{ +int err =0 ; + +switch (cmd) { +case RTM_SETLINK : +if (p) { + err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); +if (err) +break ; + +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) + err =br_vlan_add (p->br, vinfo->vid, + vinfo->flags); + }else { + err =br_vlan_add (br, vinfo->vid, vinfo->flags); + } +break ; + +case RTM_DELLINK : +if (p) { +nbp_vlan_delete (p, vinfo->vid); +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) +br_vlan_delete (p->br, vinfo->vid); + }else { +br_vlan_delete (br, vinfo->vid); + } +break ; + } + +return err; +} +static int br_afspec (struct net_bridge *br,struct net_bridge_port *p,struct nlattr *af_spec,int cmd) {struct nlattr *tb[IFLA_BRIDGE_MAX +1 ]; +struct nlattr *attr;int err =0 ; +int rem; err =nla_parse_nested (tb,IFLA_BRIDGE_MAX , af_spec, ifla_br_policy);if (err)return err;if (tb[IFLA_BRIDGE_VLAN_INFO ]) { -struct bridge_vlan_info *vinfo; - - vinfo =nla_data (tb[IFLA_BRIDGE_VLAN_INFO ]); - -if (!vinfo->vid || vinfo->vid >=VLAN_VID_MASK ) -return -EINVAL ; - -switch (cmd) { -case RTM_SETLINK : -if (p) { - err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); -if (err) -break ; - -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) - err =br_vlan_add (p->br, vinfo->vid, - vinfo->flags); - }else - err =br_vlan_add (br, vinfo->vid, vinfo->flags); - -break ; - -case RTM_DELLINK : -if (p) { -nbp_vlan_delete (p, vinfo->vid); -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) -br_vlan_delete (p->br, vinfo->vid); - }else -br_vlan_delete (br, vinfo->vid); -break ; + attr = tb[IFLA_BRIDGE_VLAN_INFO ]; +if (nla_len (attr) !=sizeof (struct bridge_vlan_info )) + goto err_inval; + + err =br_vlan_info (br, p, cmd, + (struct bridge_vlan_info *)nla_data (attr)); + + }else if (tb[IFLA_BRIDGE_VLAN_INFO_LIST ]) { +struct bridge_vlan_info *vinfo_start =NULL ; +struct bridge_vlan_info *vinfo =NULL ; + +nla_for_each_nested (attr, tb[IFLA_BRIDGE_VLAN_INFO_LIST ], rem) { +if (nla_len (attr) !=sizeof (struct bridge_vlan_info ) || +nla_type (attr) !=IFLA_BRIDGE_VLAN_INFO ) + goto err_inval; + vinfo =nla_data (attr); +if (vinfo->flags &BRIDGE_VLAN_INFO_RANGE_START ) { +if (vinfo_start) + goto err_inval; + vinfo_start = vinfo; +continue ; + } + +if (vinfo_start) { +int v;Quoted 8 lines
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 307
Quoted 5 lines
net/bridge/br_netlink.c +5
-0+ +if (!(vinfo->flags &BRIDGE_VLAN_INFO_RANGE_END )) + goto err_inval; + +if (vinfo->vid < vinfo_start->vid)This check rejects inverted range. However it allows the
RANGE_STARTandRANGE_ENDvinfos to have the same vid. Isn't it inconsistent with the rejection of a single vinfo with bothRANGE_STARTandRANGE_ENDset?
Quoted 2 lines
Allowing both START and END to be set on single vinfo might simplify the encoding of LIST, so maybe it should be allowed.
sorry, i did not understand this. How does it help ?.
Quoted 8 lines
Roopa, I know you dropped the subsequent notification patches from the set, but I suspect now with these new START/END markers, the notification algorithm can be very close to the original loop, without having to make copies of the
vlan_bitmapanduntagged_bitmap.
Using
both START/END on a single vinfo will keep the loop simple for adding single vids that are not in a range.
The way i am seeing it is, both, making copies of vlan_bitmap and using the existing loop can be used with both old and the new proposed netlink attributes (unless i am missing something). Our original in-house code used copies of vlan bitmap (not authored by me) and it was well tested,
so it was safer to post that code in terms of testing effort.
But during the course of this review, i do realize that the existing loop can be used. And now i see that the existing loop
can be used with both the old proposed and the new netlink formats. I have coded up the patches. In the process of testing it. Will post the new series soon. Maybe you will spot something.
Quoted 3 lines
(hmmm...START/STOP or BEGIN/END? Seems START/END is mixing the two concepts...BEGIN/END seems best)
Sure, no preference there. I will use BEGIN/END.
Thanks,
Roopa
Quoted 89 lines · On Wed, Dec 31, 2014 at 8:48 AM, <[email protected]> wrote:
From: Roopa Prabhu <[email protected]>
This patch modifies
br_afspecto parse incomingIFLA_BRIDGE_VLAN_INFO_LISTSigned-off-by Roopa Prabhu <[email protected]>--- net/bridge/br_netlink.c | 115 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 30 deletions(-)net/bridge/br_netlink.c +36
-23@@ -226,53 +226,108 @@ static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { [IFLA_BRIDGE_VLAN_INFO_LIST] = { .type = NLA_NESTED, }, }; +static int br_vlan_info (struct net_bridge *br,struct net_bridge_port *p, +int cmd,struct bridge_vlan_info *vinfo) +{ +int err =0 ; + +switch (cmd) { +case RTM_SETLINK : +if (p) { + err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); +if (err) +break ; + +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) + err =br_vlan_add (p->br, vinfo->vid, + vinfo->flags); + }else { + err =br_vlan_add (br, vinfo->vid, vinfo->flags); + } +break ; + +case RTM_DELLINK : +if (p) { +nbp_vlan_delete (p, vinfo->vid); +if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) +br_vlan_delete (p->br, vinfo->vid); + }else { +br_vlan_delete (br, vinfo->vid); + } +break ; + } + +return err; +} +static int br_afspec (struct net_bridge *br,struct net_bridge_port *p,struct nlattr *af_spec,int cmd) {struct nlattr *tb[IFLA_BRIDGE_MAX +1 ]; +struct nlattr *attr;int err =0 ; +int rem; err =nla_parse_nested (tb,IFLA_BRIDGE_MAX , af_spec, ifla_br_policy);if (err)return err;if (tb[IFLA_BRIDGE_VLAN_INFO ]) { -struct bridge_vlan_info *vinfo; - - vinfo =nla_data (tb[IFLA_BRIDGE_VLAN_INFO ]); - -if (!vinfo->vid || vinfo->vid >=VLAN_VID_MASK ) -return -EINVAL ; - -switch (cmd) { -case RTM_SETLINK : -if (p) { - err =nbp_vlan_add (p, vinfo->vid, vinfo->flags); -if (err) -break ; - -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) - err =br_vlan_add (p->br, vinfo->vid, - vinfo->flags); - }else - err =br_vlan_add (br, vinfo->vid, vinfo->flags); - -break ; - -case RTM_DELLINK :
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 280
Quoted 10 lines
net/bridge/br_netlink.c +3
-7-if (p) { -nbp_vlan_delete (p, vinfo->vid); -if (vinfo->flags &BRIDGE_VLAN_INFO_MASTER ) -br_vlan_delete (p->br, vinfo->vid); - }else -br_vlan_delete (br, vinfo->vid); -break ; + attr = tb[IFLA_BRIDGE_VLAN_INFO ]; +if (nla_len (attr) !=sizeof (struct bridge_vlan_info )) + goto err_inval;
Size check isn't necessary here as it was already done with nla_parse_nested().
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 285
Quoted 5 lines
net/bridge/br_netlink.c +5
-0+ + err =br_vlan_info (br, p, cmd, + (struct bridge_vlan_info *)nla_data (attr)); + + }else if (tb[IFLA_BRIDGE_VLAN_INFO_LIST ]) {
Could you have both IFLA_BRIDGE_VLAN_INFO and IFLA_BRIDGE_VLAN_INFO_LIST? If so, drop the else.
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 287
Quoted 2 lines
net/bridge/br_netlink.c +2
-0+struct bridge_vlan_info *vinfo_start =NULL ; +struct bridge_vlan_info *vinfo =NULL ;
Initializer not needed on this ^^^ one.
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 292
Quoted 5 lines
net/bridge/br_netlink.c +5
-0+ +nla_for_each_nested (attr, tb[IFLA_BRIDGE_VLAN_INFO_LIST ], rem) { +if (nla_len (attr) !=sizeof (struct bridge_vlan_info ) || +nla_type (attr) !=IFLA_BRIDGE_VLAN_INFO ) + goto err_inval;
goto isn't necessary...just return -EINVAL...more like this below
Quoted 9 lines
net/bridge/br_netlink.c +9
-0+ vinfo =nla_data (attr); +if (vinfo->flags &BRIDGE_VLAN_INFO_RANGE_START ) { +if (vinfo_start) + goto err_inval; + vinfo_start = vinfo; +continue ; + } + +if (vinfo_start) {
net/bridge/br_netlink.c static const struct nla_policy ifla_br_policy[IFLA_MAX+1] = { · line 311
Quoted 10 lines
net/bridge/br_netlink.c +10
-0+int v; + +if (!(vinfo->flags &BRIDGE_VLAN_INFO_RANGE_END )) + goto err_inval; + +if (vinfo->vid < vinfo_start->vid) + goto err_inval; + +for (v = vinfo_start->vid; v <= vinfo->vid; + v++) {
Did the above exceed 80 chars? If not, one liner.
Quoted 25 lines
net/bridge/br_netlink.c +15
-1+ vinfo_start->vid = v; + err =br_vlan_info (br, p, cmd, + vinfo_start); +if (err) +break ; + } + vinfo_start =NULL ; + }else { + err =br_vlan_info (br, p, cmd, vinfo); + } +if (err) +break ; } }return err; + +err_inval: +return -EINVAL ; }static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX +1 ] = { --1.7.10.4