IPv6 address configuration conversions
Subsystems (3)
PATCH 1/1 IPv6 address configuration conversions
Converts all of the IPv6 address configuration code to the new netlink api and removes a bogus check on IFF_UP when adding new addresses.
Signature · 1 line
VGER BF report: U 0.467674
PATCH 1/8 address: Convert address addition to new netlink api
net/ipv6/addrconf.c +45 -27
@@ -2868,6 +2868,29 @@spin_unlock_bh (&addrconf_verify_lock); } +static struct in6_addr *extract_addr (struct nlattr *addr,struct nlattr *local) +{ +struct in6_addr *pfx =NULL ; + +if (addr) + pfx =nla_data (addr); + +if (local) { +if (pfx &&nla_memcmp (local, pfx,sizeof (*pfx))) + pfx =NULL ; +else + pfx =nla_data (local); + } + +return pfx; +} + +static struct nla_policy ifa_ipv6_policy[IFA_MAX +1 ]__read_mostly = { + [IFA_ADDRESS ] = { .len =sizeof (struct in6_addr ) }, + [IFA_LOCAL ] = { .len =sizeof (struct in6_addr ) }, + [IFA_CACHEINFO ] = { .len =sizeof (struct ifa_cacheinfo ) }, +}; +static int inet6_rtm_deladdr (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg) {
@@ -2945,46 +2968,41 @@static int inet6_rtm_newaddr (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg) { -struct rtattr **rta = arg; -struct ifaddrmsg *ifm =NLMSG_DATA (nlh); +struct ifaddrmsg *ifm; +struct nlattr *tb[IFA_MAX +1 ];struct in6_addr *pfx; -__u32 valid_lft =INFINITY_LIFE_TIME , prefered_lft =INFINITY_LIFE_TIME ; +u32 valid_lft, preferred_lft; +int err; - pfx =NULL ; -if (rta[IFA_ADDRESS -1 ]) { -if (RTA_PAYLOAD (rta[IFA_ADDRESS -1 ]) <sizeof (*pfx)) -return -EINVAL ; - pfx =RTA_DATA (rta[IFA_ADDRESS -1 ]); - } -if (rta[IFA_LOCAL -1 ]) { -if (RTA_PAYLOAD (rta[IFA_LOCAL -1 ]) <sizeof (*pfx) || - (pfx &&memcmp (pfx,RTA_DATA (rta[IFA_LOCAL -1 ]),sizeof (*pfx)))) -return -EINVAL ; - pfx =RTA_DATA (rta[IFA_LOCAL -1 ]); - } + err =nlmsg_parse (nlh,sizeof (*ifm), tb,IFA_MAX , ifa_ipv6_policy); +if (err <0 ) +return err; + + ifm =nlmsg_data (nlh); + pfx =extract_addr (tb[IFA_ADDRESS ], tb[IFA_LOCAL ]);if (pfx ==NULL )return -EINVAL ; -if (rta[IFA_CACHEINFO -1 ]) { +if (tb[IFA_CACHEINFO ]) {struct ifa_cacheinfo *ci; -if (RTA_PAYLOAD (rta[IFA_CACHEINFO -1 ]) <sizeof (*ci)) -return -EINVAL ; - ci =RTA_DATA (rta[IFA_CACHEINFO -1 ]); + + ci =nla_data (tb[IFA_CACHEINFO ]); valid_lft = ci->ifa_valid; - prefered_lft = ci->ifa_prefered; + preferred_lft = ci->ifa_prefered; + }else { + preferred_lft =INFINITY_LIFE_TIME ; + valid_lft =INFINITY_LIFE_TIME ; }if (nlh->nlmsg_flags &NLM_F_REPLACE ) { -int ret; - ret =inet6_addr_modify (ifm->ifa_index, pfx, - prefered_lft, valid_lft); -if (ret ==0 || !(nlh->nlmsg_flags &NLM_F_CREATE )) -return ret; + err =inet6_addr_modify (ifm->ifa_index, pfx, + preferred_lft, valid_lft); +if (err ==0 || !(nlh->nlmsg_flags &NLM_F_CREATE )) +return err; }return inet6_addr_add (ifm->ifa_index, pfx, ifm->ifa_prefixlen, - prefered_lft, valid_lft); - + preferred_lft, valid_lft); }/* Maximum length of ifa_cacheinfo attributes */
Signature · 1 line
VGER BF report: H 0.0247949
Re: [PATCH 1/8] address: Convert address addition to new netlink api
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:39:58 +0200
Quoted 1 line
Signed-off-by Thomas Graf <[email protected]>
Applied.
PATCH 2/8 address: Convert address deletion to new netlink api
In reply to Thomas Grafnet/ipv6/addrconf.c +9 -14
@@ -2894,22 +2894,17 @@static int inet6_rtm_deladdr (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg) { -struct rtattr **rta = arg; -struct ifaddrmsg *ifm =NLMSG_DATA (nlh); +struct ifaddrmsg *ifm; +struct nlattr *tb[IFA_MAX +1 ];struct in6_addr *pfx; +int err; - pfx =NULL ; -if (rta[IFA_ADDRESS -1 ]) { -if (RTA_PAYLOAD (rta[IFA_ADDRESS -1 ]) <sizeof (*pfx)) -return -EINVAL ; - pfx =RTA_DATA (rta[IFA_ADDRESS -1 ]); - } -if (rta[IFA_LOCAL -1 ]) { -if (RTA_PAYLOAD (rta[IFA_LOCAL -1 ]) <sizeof (*pfx) || - (pfx &&memcmp (pfx,RTA_DATA (rta[IFA_LOCAL -1 ]),sizeof (*pfx)))) -return -EINVAL ; - pfx =RTA_DATA (rta[IFA_LOCAL -1 ]); - } + err =nlmsg_parse (nlh,sizeof (*ifm), tb,IFA_MAX , ifa_ipv6_policy); +if (err <0 ) +return err; + + ifm =nlmsg_data (nlh); + pfx =extract_addr (tb[IFA_ADDRESS ], tb[IFA_LOCAL ]);if (pfx ==NULL )return -EINVAL ;
Signature · 1 line
VGER BF report: H 0.0599509
Re: [PATCH 2/8] address: Convert address deletion to new netlink api
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:39:59 +0200
Quoted 1 line
Signed-off-by Thomas Graf <[email protected]>
Applied.
PATCH 3/8 address: Convert address lookup to new netlink api
In reply to Thomas Grafnet/ipv6/addrconf.c +24 -28
@@ -3234,58 +3234,54 @@return inet6_dump_addr (skb, cb, type); } -static int inet6_rtm_getaddr (struct sk_buff *in_skb, -struct nlmsghdr * nlh,void *arg) +static int inet6_rtm_getaddr (struct sk_buff *in_skb,struct nlmsghdr * nlh, +void *arg) { -struct rtattr **rta = arg; -struct ifaddrmsg *ifm =NLMSG_DATA (nlh); +struct ifaddrmsg *ifm; +struct nlattr *tb[IFA_MAX +1 ];struct in6_addr *addr =NULL ;struct net_device *dev =NULL ;struct inet6_ifaddr *ifa;struct sk_buff *skb; -int size =NLMSG_SPACE (sizeof (struct ifaddrmsg ) +INET6_IFADDR_RTA_SPACE ); +int payload =sizeof (struct ifaddrmsg ) +INET6_IFADDR_RTA_SPACE ;int err; -if (rta[IFA_ADDRESS -1 ]) { -if (RTA_PAYLOAD (rta[IFA_ADDRESS -1 ]) <sizeof (*addr)) -return -EINVAL ; - addr =RTA_DATA (rta[IFA_ADDRESS -1 ]); - } -if (rta[IFA_LOCAL -1 ]) { -if (RTA_PAYLOAD (rta[IFA_LOCAL -1 ]) <sizeof (*addr) || - (addr &&memcmp (addr,RTA_DATA (rta[IFA_LOCAL -1 ]),sizeof (*addr)))) -return -EINVAL ; - addr =RTA_DATA (rta[IFA_LOCAL -1 ]); + err =nlmsg_parse (nlh,sizeof (*ifm), tb,IFA_MAX , ifa_ipv6_policy); +if (err <0 ) + goto errout; + + addr =extract_addr (tb[IFA_ADDRESS ], tb[IFA_LOCAL ]); +if (addr ==NULL ) { + err = -EINVAL ; + goto errout; } -if (addr ==NULL ) -return -EINVAL ; + ifm =nlmsg_data (nlh);if (ifm->ifa_index) dev =__dev_get_by_index (ifm->ifa_index); -if ((ifa =ipv6_get_ifaddr (addr, dev,1 )) ==NULL ) -return -EADDRNOTAVAIL ; +if ((ifa =ipv6_get_ifaddr (addr, dev,1 )) ==NULL ) { + err = -EADDRNOTAVAIL ; + goto errout; + } -if ((skb =alloc_skb (size,GFP_KERNEL )) ==NULL ) { +if ((skb =nlmsg_new (nlmsg_total_size (payload),GFP_KERNEL )) ==NULL ) { err = -ENOBUFS ; - goto out; + goto errout_ifa; } -NETLINK_CB (skb).dst_pid =NETLINK_CB (in_skb).pid; err =inet6_fill_ifaddr (skb, ifa,NETLINK_CB (in_skb).pid, nlh->nlmsg_seq,RTM_NEWADDR ,0 );if (err <0 ) { - err = -EMSGSIZE ; - goto out_free; +kfree_skb (skb); + goto errout_ifa; } err =rtnl_unicast (skb,NETLINK_CB (in_skb).pid); -out: +errout_ifa:in6_ifa_put (ifa); +errout:return err; -out_free: -kfree_skb (skb); - goto out; }static void inet6_ifa_notify (int event,struct inet6_ifaddr *ifa)
Signature · 1 line
VGER BF report: H 0.00657627
Re: [PATCH 3/8] address: Convert address lookup to new netlink api
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:40:00 +0200
Quoted 1 line
Signed-off-by Thomas Graf <[email protected]>
Applied.
PATCH 4/8 address: Add put_cacheinfo() to dump struct cacheinfo
In reply to Thomas Grafnet/ipv6/addrconf.c +38 -34
@@ -3000,6 +3000,21 @@ preferred_lft, valid_lft); } +static int put_cacheinfo (struct sk_buff *skb,unsigned long cstamp, +unsigned long tstamp,u32 preferred,u32 valid) +{ +struct ifa_cacheinfo ci; + + ci.cstamp = (u32)(TIME_DELTA (cstamp,INITIAL_JIFFIES ) /HZ *100 + +TIME_DELTA (cstamp,INITIAL_JIFFIES ) %HZ *100 /HZ ); + ci.tstamp = (u32)(TIME_DELTA (tstamp,INITIAL_JIFFIES ) /HZ *100 + +TIME_DELTA (tstamp,INITIAL_JIFFIES ) %HZ *100 /HZ ); + ci.ifa_prefered = preferred; + ci.ifa_valid = valid; + +return nla_put (skb,IFA_CACHEINFO ,sizeof (ci), &ci); +} +/* Maximum length of ifa_cacheinfo attributes */ #define INET6_IFADDR_RTA_SPACE \ RTA_SPACE(16) /* IFA_ADDRESS */ + \
@@ -3010,8 +3025,8 @@ {struct ifaddrmsg *ifm;struct nlmsghdr *nlh; -struct ifa_cacheinfo ci;unsigned char *b = skb->tail; +u32 preferred, valid; nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*ifm), flags); ifm =NLMSG_DATA (nlh);
@@ -3028,23 +3043,22 @@ ifm->ifa_index = ifa->idev->dev->ifindex;RTA_PUT (skb,IFA_ADDRESS ,16 , &ifa->addr);if (!(ifa->flags&IFA_F_PERMANENT )) { - ci.ifa_prefered = ifa->prefered_lft; - ci.ifa_valid = ifa->valid_lft; -if (ci.ifa_prefered !=INFINITY_LIFE_TIME ) { + preferred = ifa->prefered_lft; + valid = ifa->valid_lft; +if (preferred !=INFINITY_LIFE_TIME ) {long tval = (jiffies - ifa->tstamp)/HZ ; - ci.ifa_prefered -= tval; -if (ci.ifa_valid !=INFINITY_LIFE_TIME ) - ci.ifa_valid -= tval; + preferred -= tval; +if (valid !=INFINITY_LIFE_TIME ) + valid -= tval; } }else { - ci.ifa_prefered =INFINITY_LIFE_TIME ; - ci.ifa_valid =INFINITY_LIFE_TIME ; + preferred =INFINITY_LIFE_TIME ; + valid =INFINITY_LIFE_TIME ; } - ci.cstamp = (__u32)(TIME_DELTA (ifa->cstamp,INITIAL_JIFFIES ) /HZ *100 - +TIME_DELTA (ifa->cstamp,INITIAL_JIFFIES ) %HZ *100 /HZ ); - ci.tstamp = (__u32)(TIME_DELTA (ifa->tstamp,INITIAL_JIFFIES ) /HZ *100 - +TIME_DELTA (ifa->tstamp,INITIAL_JIFFIES ) %HZ *100 /HZ ); -RTA_PUT (skb,IFA_CACHEINFO ,sizeof (ci), &ci); + +if (put_cacheinfo (skb, ifa->cstamp, ifa->tstamp, preferred, valid) <0 ) + goto rtattr_failure; + nlh->nlmsg_len = skb->tail - b;return skb->len;
@@ -3059,7 +3073,6 @@ {struct ifaddrmsg *ifm;struct nlmsghdr *nlh; -struct ifa_cacheinfo ci;unsigned char *b = skb->tail; nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*ifm), flags);
@@ -3072,15 +3085,11 @@ ifm->ifa_scope =RT_SCOPE_SITE ; ifm->ifa_index = ifmca->idev->dev->ifindex;RTA_PUT (skb,IFA_MULTICAST ,16 , &ifmca->mca_addr); - ci.cstamp = (__u32)(TIME_DELTA (ifmca->mca_cstamp,INITIAL_JIFFIES ) /HZ - *100 +TIME_DELTA (ifmca->mca_cstamp,INITIAL_JIFFIES ) %HZ - *100 /HZ ); - ci.tstamp = (__u32)(TIME_DELTA (ifmca->mca_tstamp,INITIAL_JIFFIES ) /HZ - *100 +TIME_DELTA (ifmca->mca_tstamp,INITIAL_JIFFIES ) %HZ - *100 /HZ ); - ci.ifa_prefered =INFINITY_LIFE_TIME ; - ci.ifa_valid =INFINITY_LIFE_TIME ; -RTA_PUT (skb,IFA_CACHEINFO ,sizeof (ci), &ci); + +if (put_cacheinfo (skb, ifmca->mca_cstamp, ifmca->mca_tstamp, +INFINITY_LIFE_TIME ,INFINITY_LIFE_TIME ) <0 ) + goto rtattr_failure; + nlh->nlmsg_len = skb->tail - b;return skb->len;
@@ -3095,7 +3104,6 @@ {struct ifaddrmsg *ifm;struct nlmsghdr *nlh; -struct ifa_cacheinfo ci;unsigned char *b = skb->tail; nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*ifm), flags);
@@ -3108,15 +3116,11 @@ ifm->ifa_scope =RT_SCOPE_SITE ; ifm->ifa_index = ifaca->aca_idev->dev->ifindex;RTA_PUT (skb,IFA_ANYCAST ,16 , &ifaca->aca_addr); - ci.cstamp = (__u32)(TIME_DELTA (ifaca->aca_cstamp,INITIAL_JIFFIES ) /HZ - *100 +TIME_DELTA (ifaca->aca_cstamp,INITIAL_JIFFIES ) %HZ - *100 /HZ ); - ci.tstamp = (__u32)(TIME_DELTA (ifaca->aca_tstamp,INITIAL_JIFFIES ) /HZ - *100 +TIME_DELTA (ifaca->aca_tstamp,INITIAL_JIFFIES ) %HZ - *100 /HZ ); - ci.ifa_prefered =INFINITY_LIFE_TIME ; - ci.ifa_valid =INFINITY_LIFE_TIME ; -RTA_PUT (skb,IFA_CACHEINFO ,sizeof (ci), &ci); + +if (put_cacheinfo (skb, ifaca->aca_cstamp, ifaca->aca_tstamp, +INFINITY_LIFE_TIME ,INFINITY_LIFE_TIME ) <0 ) + goto rtattr_failure; + nlh->nlmsg_len = skb->tail - b;return skb->len;
Signature · 1 line
VGER BF report: H 0.000143698
Re: [PATCH 4/8] address: Add put_cacheinfo() to dump struct cacheinfo
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:40:01 +0200
Quoted 1 line
Signed-off-by Thomas Graf <[email protected]>
Applied, thanks.
PATCH 5/8 address: Add put_ifaddrmsg() and rt_scope()
In reply to Thomas Grafnet/ipv6/addrconf.c +43 -34
@@ -3000,6 +3000,19 @@ preferred_lft, valid_lft); } +static void put_ifaddrmsg (struct nlmsghdr *nlh,u8 prefixlen,u8 flags, +u8 scope,int ifindex) +{ +struct ifaddrmsg *ifm; + + ifm =nlmsg_data (nlh); + ifm->ifa_family =AF_INET6 ; + ifm->ifa_prefixlen = prefixlen; + ifm->ifa_flags = flags; + ifm->ifa_scope = scope; + ifm->ifa_index = ifindex; +} +static int put_cacheinfo (struct sk_buff *skb,unsigned long cstamp,unsigned long tstamp,u32 preferred,u32 valid) {
@@ -3015,6 +3028,18 @@return nla_put (skb,IFA_CACHEINFO ,sizeof (ci), &ci); } +static inline int rt_scope (int ifa_scope) +{ +if (ifa_scope &IFA_HOST ) +return RT_SCOPE_HOST ; +else if (ifa_scope &IFA_LINK ) +return RT_SCOPE_LINK ; +else if (ifa_scope &IFA_SITE ) +return RT_SCOPE_SITE ; +else +return RT_SCOPE_UNIVERSE ; +} +/* Maximum length of ifa_cacheinfo attributes */ #define INET6_IFADDR_RTA_SPACE \ RTA_SPACE(16) /* IFA_ADDRESS */ + \
@@ -3023,24 +3048,14 @@static int inet6_fill_ifaddr (struct sk_buff *skb,struct inet6_ifaddr *ifa,u32 pid,u32 seq,int event,unsigned int flags) { -struct ifaddrmsg *ifm;struct nlmsghdr *nlh;unsigned char *b = skb->tail;u32 preferred, valid; - nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*ifm), flags); - ifm =NLMSG_DATA (nlh); - ifm->ifa_family =AF_INET6 ; - ifm->ifa_prefixlen = ifa->prefix_len; - ifm->ifa_flags = ifa->flags; - ifm->ifa_scope =RT_SCOPE_UNIVERSE ; -if (ifa->scope&IFA_HOST ) - ifm->ifa_scope =RT_SCOPE_HOST ; -else if (ifa->scope&IFA_LINK ) - ifm->ifa_scope =RT_SCOPE_LINK ; -else if (ifa->scope&IFA_SITE ) - ifm->ifa_scope =RT_SCOPE_SITE ; - ifm->ifa_index = ifa->idev->dev->ifindex; + nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); +put_ifaddrmsg (nlh, ifa->prefix_len, ifa->flags,rt_scope (ifa->scope), + ifa->idev->dev->ifindex); +RTA_PUT (skb,IFA_ADDRESS ,16 , &ifa->addr);if (!(ifa->flags&IFA_F_PERMANENT )) { preferred = ifa->prefered_lft;
@@ -3071,19 +3086,16 @@static int inet6_fill_ifmcaddr (struct sk_buff *skb,struct ifmcaddr6 *ifmca,u32 pid,u32 seq,int event,u16 flags) { -struct ifaddrmsg *ifm;struct nlmsghdr *nlh;unsigned char *b = skb->tail; +u8 scope =RT_SCOPE_UNIVERSE ; +int ifindex = ifmca->idev->dev->ifindex; + +if (ipv6_addr_scope (&ifmca->mca_addr) &IFA_SITE ) + scope =RT_SCOPE_SITE ; - nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*ifm), flags); - ifm =NLMSG_DATA (nlh); - ifm->ifa_family =AF_INET6 ; - ifm->ifa_prefixlen =128 ; - ifm->ifa_flags =IFA_F_PERMANENT ; - ifm->ifa_scope =RT_SCOPE_UNIVERSE ; -if (ipv6_addr_scope (&ifmca->mca_addr)&IFA_SITE ) - ifm->ifa_scope =RT_SCOPE_SITE ; - ifm->ifa_index = ifmca->idev->dev->ifindex; + nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); +put_ifaddrmsg (nlh,128 ,IFA_F_PERMANENT , scope, ifindex);RTA_PUT (skb,IFA_MULTICAST ,16 , &ifmca->mca_addr); if (put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
@@ -3102,19 +3114,16 @@static int inet6_fill_ifacaddr (struct sk_buff *skb,struct ifacaddr6 *ifaca,u32 pid,u32 seq,int event,unsigned int flags) { -struct ifaddrmsg *ifm;struct nlmsghdr *nlh;unsigned char *b = skb->tail; +u8 scope =RT_SCOPE_UNIVERSE ; +int ifindex = ifaca->aca_idev->dev->ifindex; + +if (ipv6_addr_scope (&ifaca->aca_addr) &IFA_SITE ) + scope =RT_SCOPE_SITE ; - nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*ifm), flags); - ifm =NLMSG_DATA (nlh); - ifm->ifa_family =AF_INET6 ; - ifm->ifa_prefixlen =128 ; - ifm->ifa_flags =IFA_F_PERMANENT ; - ifm->ifa_scope =RT_SCOPE_UNIVERSE ; -if (ipv6_addr_scope (&ifaca->aca_addr)&IFA_SITE ) - ifm->ifa_scope =RT_SCOPE_SITE ; - ifm->ifa_index = ifaca->aca_idev->dev->ifindex; + nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); +put_ifaddrmsg (nlh,128 ,IFA_F_PERMANENT , scope, ifindex);RTA_PUT (skb,IFA_ANYCAST ,16 , &ifaca->aca_addr); if (put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
Signature · 1 line
VGER BF report: H 7.82266e-05
Re: [PATCH 5/8] address: Add put_ifaddrmsg() and rt_scope()
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:40:02 +0200
Quoted 1 line
Signed-off-by Thomas Graf <[email protected]>
Applied.
PATCH 6/8 address: Convert address dumping to new netlink api
In reply to Thomas GrafReplaces INET6_IFADDR_RTA_SPACE with a new function calculating the total required message size for all address messages.
net/ipv6/addrconf.c +33 -46
@@ -3040,23 +3040,27 @@return RT_SCOPE_UNIVERSE ; } -/* Maximum length of ifa_cacheinfo attributes */ -#define INET6_IFADDR_RTA_SPACE \ - RTA_SPACE(16)/* IFA_ADDRESS */ + \ - RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */ +static inline int inet6_ifaddr_msgsize (void ) +{ +return nlmsg_total_size (sizeof (struct ifaddrmsg ) + +nla_total_size (16 ) + +nla_total_size (sizeof (struct ifa_cacheinfo )) + +128 ); +}static int inet6_fill_ifaddr (struct sk_buff *skb,struct inet6_ifaddr *ifa,u32 pid,u32 seq,int event,unsigned int flags) {struct nlmsghdr *nlh; -unsigned char *b = skb->tail;u32 preferred, valid; - nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); + nlh =nlmsg_put (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); +if (nlh ==NULL ) +return -ENOBUFS ; +put_ifaddrmsg (nlh, ifa->prefix_len, ifa->flags,rt_scope (ifa->scope), ifa->idev->dev->ifindex); -RTA_PUT (skb,IFA_ADDRESS ,16 , &ifa->addr);if (!(ifa->flags&IFA_F_PERMANENT )) { preferred = ifa->prefered_lft; valid = ifa->valid_lft;
@@ -3071,72 +3075,57 @@ valid =INFINITY_LIFE_TIME ; } -if (put_cacheinfo (skb, ifa->cstamp, ifa->tstamp, preferred, valid) <0 ) - goto rtattr_failure; - - nlh->nlmsg_len = skb->tail - b; -return skb->len; +if (nla_put (skb,IFA_ADDRESS ,16 , &ifa->addr) <0 || +put_cacheinfo (skb, ifa->cstamp, ifa->tstamp, preferred, valid) <0 ) +return nlmsg_cancel (skb, nlh); -nlmsg_failure: -rtattr_failure: -skb_trim (skb, b - skb->data); -return -1 ; +return nlmsg_end (skb, nlh); }static int inet6_fill_ifmcaddr (struct sk_buff *skb,struct ifmcaddr6 *ifmca,u32 pid,u32 seq,int event,u16 flags) {struct nlmsghdr *nlh; -unsigned char *b = skb->tail;u8 scope =RT_SCOPE_UNIVERSE ;int ifindex = ifmca->idev->dev->ifindex;if (ipv6_addr_scope (&ifmca->mca_addr) &IFA_SITE ) scope =RT_SCOPE_SITE ; - nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); -put_ifaddrmsg (nlh,128 ,IFA_F_PERMANENT , scope, ifindex); -RTA_PUT (skb,IFA_MULTICAST ,16 , &ifmca->mca_addr); + nlh =nlmsg_put (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); +if (nlh ==NULL ) +return -ENOBUFS ; -if (put_cacheinfo (skb, ifmca->mca_cstamp, ifmca->mca_tstamp, +put_ifaddrmsg (nlh,128 ,IFA_F_PERMANENT , scope, ifindex); +if (nla_put (skb,IFA_MULTICAST ,16 , &ifmca->mca_addr) <0 || +put_cacheinfo (skb, ifmca->mca_cstamp, ifmca->mca_tstamp,INFINITY_LIFE_TIME ,INFINITY_LIFE_TIME ) <0 ) - goto rtattr_failure; - - nlh->nlmsg_len = skb->tail - b; -return skb->len; +return nlmsg_cancel (skb, nlh); -nlmsg_failure: -rtattr_failure: -skb_trim (skb, b - skb->data); -return -1 ; +return nlmsg_end (skb, nlh); }static int inet6_fill_ifacaddr (struct sk_buff *skb,struct ifacaddr6 *ifaca,u32 pid,u32 seq,int event,unsigned int flags) {struct nlmsghdr *nlh; -unsigned char *b = skb->tail;u8 scope =RT_SCOPE_UNIVERSE ;int ifindex = ifaca->aca_idev->dev->ifindex;if (ipv6_addr_scope (&ifaca->aca_addr) &IFA_SITE ) scope =RT_SCOPE_SITE ; - nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); -put_ifaddrmsg (nlh,128 ,IFA_F_PERMANENT , scope, ifindex); -RTA_PUT (skb,IFA_ANYCAST ,16 , &ifaca->aca_addr); + nlh =nlmsg_put (skb, pid, seq, event,sizeof (struct ifaddrmsg ), flags); +if (nlh ==NULL ) +return -ENOBUFS ; -if (put_cacheinfo (skb, ifaca->aca_cstamp, ifaca->aca_tstamp, +put_ifaddrmsg (nlh,128 ,IFA_F_PERMANENT , scope, ifindex); +if (nla_put (skb,IFA_ANYCAST ,16 , &ifaca->aca_addr) <0 || +put_cacheinfo (skb, ifaca->aca_cstamp, ifaca->aca_tstamp,INFINITY_LIFE_TIME ,INFINITY_LIFE_TIME ) <0 ) - goto rtattr_failure; +return nlmsg_cancel (skb, nlh); - nlh->nlmsg_len = skb->tail - b; -return skb->len; - -nlmsg_failure: -rtattr_failure: -skb_trim (skb, b - skb->data); -return -1 ; +return nlmsg_end (skb, nlh); }enum addr_type_t
@@ -3256,7 +3245,6 @@struct net_device *dev =NULL ;struct inet6_ifaddr *ifa;struct sk_buff *skb; -int payload =sizeof (struct ifaddrmsg ) +INET6_IFADDR_RTA_SPACE ;int err; err =nlmsg_parse (nlh,sizeof (*ifm), tb,IFA_MAX , ifa_ipv6_policy);
@@ -3278,7 +3266,7 @@ goto errout; } -if ((skb =nlmsg_new (nlmsg_total_size (payload),GFP_KERNEL )) ==NULL ) { +if ((skb =nlmsg_new (inet6_ifaddr_msgsize (),GFP_KERNEL )) ==NULL ) { err = -ENOBUFS ; goto errout_ifa; }
@@ -3300,10 +3288,9 @@static void inet6_ifa_notify (int event,struct inet6_ifaddr *ifa) {struct sk_buff *skb; -int payload =sizeof (struct ifaddrmsg ) +INET6_IFADDR_RTA_SPACE ;int err = -ENOBUFS ; - skb =nlmsg_new (nlmsg_total_size (payload),GFP_ATOMIC ); + skb =nlmsg_new (inet6_ifaddr_msgsize (),GFP_ATOMIC );if (skb ==NULL ) goto errout;
Signature · 1 line
VGER BF report: H 0.00178487
Re: [PATCH 6/8] address: Convert address dumping to new netlink api
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:40:03 +0200
Quoted 4 lines
Replaces
INET6_IFADDR_RTA_SPACEwith a new function calculating the total required message size for all address messages.Signed-off-by Thomas Graf <[email protected]>
Applied.
PATCH 7/8 address: Allow address changes while device is administrative down
In reply to Thomas GrafSame behaviour as IPv4, using IFF_UP is a no-no anyway.
net/ipv6/addrconf.c +0 -6
@@ -1886,9 +1886,6 @@if ((dev =__dev_get_by_index (ifindex)) ==NULL )return -ENODEV ; -if (!(dev->flags&IFF_UP )) -return -ENETDOWN ; -if ((idev =addrconf_add_dev (dev)) ==NULL )return -ENOBUFS ;
@@ -2922,9 +2919,6 @@if ((dev =__dev_get_by_index (ifindex)) ==NULL )return -ENODEV ; -if (!(dev->flags&IFF_UP )) -return -ENETDOWN ; -if (!valid_lft || (prefered_lft > valid_lft))return -EINVAL ;
Signature · 1 line
VGER BF report: H 1.17609e-05
Re: [PATCH 7/8] address: Allow address changes while device is administrative down
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:40:04 +0200
Quoted 3 lines
Same behaviour as IPv4, using
IFF_UPis a no-no anyway.Signed-off-by Thomas Graf <[email protected]>
Applied.
PATCH 8/8 address: Support NLM_F_EXCL when adding addresses
In reply to Thomas Grafiproute2 doesn't provide the NLM_F_CREATE flag when adding addresses, it is assumed to be implied. The existing code issues a check on said flag when the modify operation fails (likely due to ENOENT) before continueing to create it, this leads to a hard to predict result, therefore the NLM_F_CREATE check is removed.
net/ipv6/addrconf.c +25 -20
@@ -2908,24 +2908,14 @@return inet6_addr_del (ifm->ifa_index, pfx, ifm->ifa_prefixlen); } -static int -inet6_addr_modify (int ifindex,struct in6_addr *pfx, -__u32 prefered_lft,__u32 valid_lft) +static int inet6_addr_modify (struct inet6_ifaddr *ifp,u32 prefered_lft, +u32 valid_lft) { -struct inet6_ifaddr *ifp =NULL ; -struct net_device *dev;int ifa_flags =0 ; -if ((dev =__dev_get_by_index (ifindex)) ==NULL ) -return -ENODEV ; -if (!valid_lft || (prefered_lft > valid_lft))return -EINVAL ; - ifp =ipv6_get_ifaddr (pfx, dev,1 ); -if (ifp ==NULL ) -return -ENOENT ; -if (valid_lft ==INFINITY_LIFE_TIME ) ifa_flags =IFA_F_PERMANENT ;else if (valid_lft >=0x7FFFFFFF /HZ )
@@ -2947,7 +2937,6 @@spin_unlock_bh (&ifp->lock);if (!(ifp->flags&IFA_F_TENTATIVE ))ipv6_ifa_notify (0 , ifp); -in6_ifa_put (ifp);addrconf_verify (0 );
@@ -2960,6 +2949,8 @@struct ifaddrmsg *ifm;struct nlattr *tb[IFA_MAX +1 ];struct in6_addr *pfx; +struct inet6_ifaddr *ifa; +struct net_device *dev;u32 valid_lft, preferred_lft;int err;
@@ -2983,15 +2974,29 @@ valid_lft =INFINITY_LIFE_TIME ; } -if (nlh->nlmsg_flags &NLM_F_REPLACE ) { - err =inet6_addr_modify (ifm->ifa_index, pfx, - preferred_lft, valid_lft); -if (err ==0 || !(nlh->nlmsg_flags &NLM_F_CREATE )) -return err; + dev =__dev_get_by_index (ifm->ifa_index); +if (dev ==NULL ) +return -ENODEV ; + + ifa =ipv6_get_ifaddr (pfx, dev,1 ); +if (ifa ==NULL ) { +/* +* It would be best to check for !NLM_F_CREATE here but +* userspace alreay relies on not having to provide this. +*/ +return inet6_addr_add (ifm->ifa_index, pfx, ifm->ifa_prefixlen, + preferred_lft, valid_lft); } -return inet6_addr_add (ifm->ifa_index, pfx, ifm->ifa_prefixlen, - preferred_lft, valid_lft); +if (nlh->nlmsg_flags &NLM_F_EXCL || + !(nlh->nlmsg_flags &NLM_F_REPLACE )) + err = -EEXIST ; +else + err =inet6_addr_modify (ifa, preferred_lft, valid_lft); + +in6_ifa_put (ifa); + +return err; } static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags,
Signature · 1 line
VGER BF report: H 0.192484
David Miller
maintainerRe: [PATCH 8/8] address: Support NLM_F_EXCL when adding addresses
From: Thomas Graf <[email protected]>
Date: Fri, 01 Sep 2006 23:40:05 +0200
Quoted 7 lines
iproute2 doesn't provide the
NLM_F_CREATEflag when adding addresses, it is assumed to be implied. The existing code issues a check on said flag when the modify operation fails (likely due to ENOENT) before continueing to create it, this leads to a hard to predict result, therefore theNLM_F_CREATEcheck is removed.Signed-off-by Thomas Graf <[email protected]>
I hope this doesn't break any existing stuff, but it is certainly the logically correct thing to do. If things break I'm reverting this though.
But for now, applied, thanks.