]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - net/ipv6/addrconf.c
[IPv6] route: Simplify ip6_ins_rt()
[mirror_ubuntu-jammy-kernel.git] / net / ipv6 / addrconf.c
index c7852b38e03e451a00923481a327ffa2ce3dd5de..aafba9ea9cb6f756b15c11bacaf93cb9c3a3e2b9 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/net.h>
 #include <linux/in6.h>
 #include <linux/netdevice.h>
+#include <linux/if_addr.h>
 #include <linux/if_arp.h>
 #include <linux/if_arcnet.h>
 #include <linux/if_infiniband.h>
@@ -72,6 +73,7 @@
 #include <net/addrconf.h>
 #include <net/tcp.h>
 #include <net/ip.h>
+#include <net/netlink.h>
 #include <linux/if_tunnel.h>
 #include <linux/rtnetlink.h>
 
@@ -144,7 +146,7 @@ static int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *de
 
 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain);
 
-struct ipv6_devconf ipv6_devconf = {
+struct ipv6_devconf ipv6_devconf __read_mostly = {
        .forwarding             = 0,
        .hop_limit              = IPV6_DEFAULT_HOPLIMIT,
        .mtu6                   = IPV6_MIN_MTU,
@@ -175,7 +177,7 @@ struct ipv6_devconf ipv6_devconf = {
 #endif
 };
 
-static struct ipv6_devconf ipv6_devconf_dflt = {
+static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
        .forwarding             = 0,
        .hop_limit              = IPV6_DEFAULT_HOPLIMIT,
        .mtu6                   = IPV6_MIN_MTU,
@@ -734,7 +736,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
 
                if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
                        if (onlink == 0) {
-                               ip6_del_rt(rt, NULL, NULL, NULL);
+                               ip6_del_rt(rt);
                                rt = NULL;
                        } else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
                                rt->rt6i_expires = expires;
@@ -1525,7 +1527,7 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
        if (dev->type == ARPHRD_SIT && (dev->flags&IFF_POINTOPOINT))
                rtmsg.rtmsg_flags |= RTF_NONEXTHOP;
 
-       ip6_route_add(&rtmsg, NULL, NULL, NULL);
+       ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_PREFIX);
 }
 
 /* Create "default" multicast route to the interface */
@@ -1542,7 +1544,7 @@ static void addrconf_add_mroute(struct net_device *dev)
        rtmsg.rtmsg_ifindex = dev->ifindex;
        rtmsg.rtmsg_flags = RTF_UP;
        rtmsg.rtmsg_type = RTMSG_NEWROUTE;
-       ip6_route_add(&rtmsg, NULL, NULL, NULL);
+       ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_LOCAL);
 }
 
 static void sit_route_add(struct net_device *dev)
@@ -1559,7 +1561,7 @@ static void sit_route_add(struct net_device *dev)
        rtmsg.rtmsg_flags       = RTF_UP|RTF_NONEXTHOP;
        rtmsg.rtmsg_ifindex     = dev->ifindex;
 
-       ip6_route_add(&rtmsg, NULL, NULL, NULL);
+       ip6_route_add(&rtmsg, NULL, NULL, NULL, RT6_TABLE_MAIN);
 }
 
 static void addrconf_add_lroute(struct net_device *dev)
@@ -1660,7 +1662,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
                if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
                        if (rt->rt6i_flags&RTF_EXPIRES) {
                                if (valid_lft == 0) {
-                                       ip6_del_rt(rt, NULL, NULL, NULL);
+                                       ip6_del_rt(rt);
                                        rt = NULL;
                                } else {
                                        rt->rt6i_expires = jiffies + rt_expires;
@@ -3267,9 +3269,7 @@ static int inet6_rtm_getaddr(struct sk_buff *in_skb,
                goto out_free;
        }
 
-       err = netlink_unicast(rtnl, skb, NETLINK_CB(in_skb).pid, MSG_DONTWAIT);
-       if (err > 0)
-               err = 0;
+       err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
 out:
        in6_ifa_put(ifa);
        return err;
@@ -3281,20 +3281,23 @@ out_free:
 static void inet6_ifa_notify(int event, 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 = -ENOBUFS;
 
-       skb = alloc_skb(size, GFP_ATOMIC);
-       if (!skb) {
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, ENOBUFS);
-               return;
-       }
-       if (inet6_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) {
+       skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
+       if (skb == NULL)
+               goto errout;
+
+       err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
+       if (err < 0) {
                kfree_skb(skb);
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, EINVAL);
-               return;
+               goto errout;
        }
-       NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFADDR;
-       netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFADDR, GFP_ATOMIC);
+
+       err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
+errout:
+       if (err < 0)
+               rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
 }
 
 static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
@@ -3435,20 +3438,23 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
 {
        struct sk_buff *skb;
-       int size = NLMSG_SPACE(sizeof(struct ifinfomsg) + INET6_IFINFO_RTA_SPACE);
+       int payload = sizeof(struct ifinfomsg) + INET6_IFINFO_RTA_SPACE;
+       int err = -ENOBUFS;
        
-       skb = alloc_skb(size, GFP_ATOMIC);
-       if (!skb) {
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, ENOBUFS);
-               return;
-       }
-       if (inet6_fill_ifinfo(skb, idev, current->pid, 0, event, 0) < 0) {
+       skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
+       if (skb == NULL)
+               goto errout;
+
+       err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
+       if (err < 0) {
                kfree_skb(skb);
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, EINVAL);
-               return;
+               goto errout;
        }
-       NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFINFO;
-       netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFINFO, GFP_ATOMIC);
+
+       err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
+errout:
+       if (err < 0)
+               rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
 }
 
 /* Maximum length of prefix_cacheinfo attributes */
@@ -3500,20 +3506,23 @@ static void inet6_prefix_notify(int event, struct inet6_dev *idev,
                         struct prefix_info *pinfo)
 {
        struct sk_buff *skb;
-       int size = NLMSG_SPACE(sizeof(struct prefixmsg) + INET6_PREFIX_RTA_SPACE);
+       int payload = sizeof(struct prefixmsg) + INET6_PREFIX_RTA_SPACE;
+       int err = -ENOBUFS;
 
-       skb = alloc_skb(size, GFP_ATOMIC);
-       if (!skb) {
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, ENOBUFS);
-               return;
-       }
-       if (inet6_fill_prefix(skb, idev, pinfo, current->pid, 0, event, 0) < 0) {
+       skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
+       if (skb == NULL)
+               goto errout;
+
+       err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
+       if (err < 0) {
                kfree_skb(skb);
-               netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, EINVAL);
-               return;
+               goto errout;
        }
-       NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_PREFIX;
-       netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_PREFIX, GFP_ATOMIC);
+
+       err = rtnl_notify(skb, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
+errout:
+       if (err < 0)
+               rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX, err);
 }
 
 static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = {
@@ -3528,6 +3537,9 @@ static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = {
        [RTM_DELROUTE - RTM_BASE] = { .doit     = inet6_rtm_delroute, },
        [RTM_GETROUTE - RTM_BASE] = { .doit     = inet6_rtm_getroute,
                                      .dumpit   = inet6_dump_fib, },
+#ifdef CONFIG_IPV6_MULTIPLE_TABLES
+       [RTM_GETRULE  - RTM_BASE] = { .dumpit   = fib6_rules_dump,   },
+#endif
 };
 
 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
@@ -3536,7 +3548,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 
        switch (event) {
        case RTM_NEWADDR:
-               ip6_ins_rt(ifp->rt, NULL, NULL, NULL);
+               ip6_ins_rt(ifp->rt);
                if (ifp->idev->cnf.forwarding)
                        addrconf_join_anycast(ifp);
                break;
@@ -3545,7 +3557,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
                        addrconf_leave_anycast(ifp);
                addrconf_leave_solict(ifp->idev, &ifp->addr);
                dst_hold(&ifp->rt->u.dst);
-               if (ip6_del_rt(ifp->rt, NULL, NULL, NULL))
+               if (ip6_del_rt(ifp->rt))
                        dst_free(&ifp->rt->u.dst);
                break;
        }
@@ -3653,7 +3665,7 @@ static struct addrconf_sysctl_table
        ctl_table addrconf_conf_dir[2];
        ctl_table addrconf_proto_dir[2];
        ctl_table addrconf_root_dir[2];
-} addrconf_sysctl = {
+} addrconf_sysctl __read_mostly = {
        .sysctl_header = NULL,
        .addrconf_vars = {
                {