[lxc-devel] [lxc/master] network: Makes some routing functions static
tomponline on Github
lxc-bot at linuxcontainers.org
Tue Apr 30 09:34:32 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 496 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190430/0070addb/attachment.bin>
-------------- next part --------------
From 8f82874c8c850a2e65deed0822fe8e0c773fe213 Mon Sep 17 00:00:00 2001
From: tomponline <thomas.parrott at canonical.com>
Date: Tue, 30 Apr 2019 10:30:58 +0100
Subject: [PATCH] network: Makes some routing functions static
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 at canonical.com>
---
src/lxc/network.c | 121 +++++++++++++++++++++++-----------------------
src/lxc/network.h | 4 --
2 files changed, 60 insertions(+), 65 deletions(-)
diff --git a/src/lxc/network.c b/src/lxc/network.c
index 1f5cf00050..ec7dbccccf 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -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;
diff --git a/src/lxc/network.h b/src/lxc/network.h
index 1084cae2d4..e2757c1dba 100644
--- a/src/lxc/network.h
+++ b/src/lxc/network.h
@@ -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);
More information about the lxc-devel
mailing list