]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: Makes some routing functions static 2961/head
authortomponline <thomas.parrott@canonical.com>
Tue, 30 Apr 2019 09:30:58 +0000 (10:30 +0100)
committertomponline <thomas.parrott@canonical.com>
Tue, 30 Apr 2019 09:33:29 +0000 (10:33 +0100)
The following functions can be made static for consistency:

lxc_ipv4_dest_add
lxc_ipv6_dest_add
lxc_ip_route_dest_add (renamed)

Signed-off-by: tomponline <thomas.parrott@canonical.com>
src/lxc/network.c
src/lxc/network.h

index 1f5cf00050d2a5109b18d226bf01159a0391937d..ec7dbccccfb0929727862039ea2dafa24905adf9 100644 (file)
@@ -69,6 +69,66 @@ lxc_log_define(network, lxc);
 
 typedef int (*instantiate_cb)(struct lxc_handler *, struct lxc_netdev *);
 
+static int lxc_ip_route_dest_add(int family, int ifindex, void *dest, unsigned int netmask)
+{
+       int addrlen, err;
+       struct nl_handler nlh;
+       struct rtmsg *rt;
+       struct nlmsg *answer = NULL, *nlmsg = NULL;
+
+       addrlen = family == AF_INET ? sizeof(struct in_addr)
+                                   : sizeof(struct in6_addr);
+
+       err = netlink_open(&nlh, NETLINK_ROUTE);
+       if (err)
+               return err;
+
+       err = -ENOMEM;
+       nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
+       if (!nlmsg)
+               goto out;
+
+       answer = nlmsg_alloc_reserve(NLMSG_GOOD_SIZE);
+       if (!answer)
+               goto out;
+
+       nlmsg->nlmsghdr->nlmsg_flags =
+           NLM_F_ACK | NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
+       nlmsg->nlmsghdr->nlmsg_type = RTM_NEWROUTE;
+
+       rt = nlmsg_reserve(nlmsg, sizeof(struct rtmsg));
+       if (!rt)
+               goto out;
+       rt->rtm_family = family;
+       rt->rtm_table = RT_TABLE_MAIN;
+       rt->rtm_scope = RT_SCOPE_LINK;
+       rt->rtm_protocol = RTPROT_BOOT;
+       rt->rtm_type = RTN_UNICAST;
+       rt->rtm_dst_len = netmask;
+
+       err = -EINVAL;
+       if (nla_put_buffer(nlmsg, RTA_DST, dest, addrlen))
+               goto out;
+       if (nla_put_u32(nlmsg, RTA_OIF, ifindex))
+               goto out;
+       err = netlink_transaction(&nlh, nlmsg, answer);
+out:
+       netlink_close(&nlh);
+       nlmsg_free(answer);
+       nlmsg_free(nlmsg);
+       return err;
+}
+
+static int lxc_ipv4_dest_add(int ifindex, struct in_addr *dest, unsigned int netmask)
+{
+       return lxc_ip_route_dest_add(AF_INET, ifindex, dest, netmask);
+}
+
+static int lxc_ipv6_dest_add(int ifindex, struct in6_addr *dest, unsigned int netmask)
+{
+       return lxc_ip_route_dest_add(AF_INET6, ifindex, dest, netmask);
+}
+
 static int lxc_setup_ipv4_routes(struct lxc_list *ip, int ifindex)
 {
        struct lxc_list *iterator;
@@ -1830,67 +1890,6 @@ int lxc_ipv6_gateway_add(int ifindex, struct in6_addr *gw)
 {
        return ip_gateway_add(AF_INET6, ifindex, gw);
 }
-
-static int ip_route_dest_add(int family, int ifindex, void *dest, unsigned int netmask)
-{
-       int addrlen, err;
-       struct nl_handler nlh;
-       struct rtmsg *rt;
-       struct nlmsg *answer = NULL, *nlmsg = NULL;
-
-       addrlen = family == AF_INET ? sizeof(struct in_addr)
-                                   : sizeof(struct in6_addr);
-
-       err = netlink_open(&nlh, NETLINK_ROUTE);
-       if (err)
-               return err;
-
-       err = -ENOMEM;
-       nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
-       if (!nlmsg)
-               goto out;
-
-       answer = nlmsg_alloc_reserve(NLMSG_GOOD_SIZE);
-       if (!answer)
-               goto out;
-
-       nlmsg->nlmsghdr->nlmsg_flags =
-           NLM_F_ACK | NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
-       nlmsg->nlmsghdr->nlmsg_type = RTM_NEWROUTE;
-
-       rt = nlmsg_reserve(nlmsg, sizeof(struct rtmsg));
-       if (!rt)
-               goto out;
-       rt->rtm_family = family;
-       rt->rtm_table = RT_TABLE_MAIN;
-       rt->rtm_scope = RT_SCOPE_LINK;
-       rt->rtm_protocol = RTPROT_BOOT;
-       rt->rtm_type = RTN_UNICAST;
-       rt->rtm_dst_len = netmask;
-
-       err = -EINVAL;
-       if (nla_put_buffer(nlmsg, RTA_DST, dest, addrlen))
-               goto out;
-       if (nla_put_u32(nlmsg, RTA_OIF, ifindex))
-               goto out;
-       err = netlink_transaction(&nlh, nlmsg, answer);
-out:
-       netlink_close(&nlh);
-       nlmsg_free(answer);
-       nlmsg_free(nlmsg);
-       return err;
-}
-
-int lxc_ipv4_dest_add(int ifindex, struct in_addr *dest, unsigned int netmask)
-{
-       return ip_route_dest_add(AF_INET, ifindex, dest, netmask);
-}
-
-int lxc_ipv6_dest_add(int ifindex, struct in6_addr *dest, unsigned int netmask)
-{
-       return ip_route_dest_add(AF_INET6, ifindex, dest, netmask);
-}
-
 bool is_ovs_bridge(const char *bridge)
 {
        int ret;
index 1084cae2d46694f3072f7d9e7ec8fb7a0ff98252..e2757c1dba85ba7ccb0f104475fea79f3f6693ee 100644 (file)
@@ -222,10 +222,6 @@ extern int lxc_ipv4_addr_add(int ifindex, struct in_addr *addr,
 extern int lxc_ipv4_addr_get(int ifindex, struct in_addr **res);
 extern int lxc_ipv6_addr_get(int ifindex, struct in6_addr **res);
 
-/* Set a destination route to an interface. */
-extern int lxc_ipv4_dest_add(int ifindex, struct in_addr *dest, unsigned int netmask);
-extern int lxc_ipv6_dest_add(int ifindex, struct in6_addr *dest, unsigned int netmask);
-
 /* Set default route. */
 extern int lxc_ipv4_gateway_add(int ifindex, struct in_addr *gw);
 extern int lxc_ipv6_gateway_add(int ifindex, struct in6_addr *gw);