summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/netlink.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-01-18 13:35:11 +0100
committerNeale Ranns <nranns@cisco.com>2018-01-18 15:59:06 +0000
commit7866c4595b65f54f491ffc4e92b1f8cf94d6f142 (patch)
tree404c981a49256a66e4a95718f426d2040619fe71 /src/vnet/devices/netlink.c
parent929fb9d75071ef4141b1cac3997f86d9ded0a9ab (diff)
tapv2: add option to set host-side default gw
Change-Id: I76fd655ecd9445299b94b3b5af10e7b1588584e4 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet/devices/netlink.c')
-rw-r--r--src/vnet/devices/netlink.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/vnet/devices/netlink.c b/src/vnet/devices/netlink.c
index 5994366007c..8346b1c77ea 100644
--- a/src/vnet/devices/netlink.c
+++ b/src/vnet/devices/netlink.c
@@ -245,6 +245,48 @@ vnet_netlink_add_ip6_addr (int ifindex, void *addr, int pfx_len)
return vnet_netlink_msg_send (&m);
}
+clib_error_t *
+vnet_netlink_add_ip4_route (void *dst, u8 dst_len, void *gw)
+{
+ vnet_netlink_msg_t m;
+ struct rtmsg rtm = { 0 };
+ u8 dflt[4] = { 0 };
+
+ rtm.rtm_family = AF_INET;
+ rtm.rtm_table = RT_TABLE_MAIN;
+ rtm.rtm_type = RTN_UNICAST;
+ rtm.rtm_dst_len = dst_len;
+
+ vnet_netlink_msg_init (&m, RTM_NEWROUTE,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL,
+ &rtm, sizeof (struct rtmsg));
+
+ vnet_netlink_msg_add_rtattr (&m, RTA_GATEWAY, gw, 4);
+ vnet_netlink_msg_add_rtattr (&m, RTA_DST, dst ? dst : dflt, 4);
+ return vnet_netlink_msg_send (&m);
+}
+
+clib_error_t *
+vnet_netlink_add_ip6_route (void *dst, u8 dst_len, void *gw)
+{
+ vnet_netlink_msg_t m;
+ struct rtmsg rtm = { 0 };
+ u8 dflt[16] = { 0 };
+
+ rtm.rtm_family = AF_INET6;
+ rtm.rtm_table = RT_TABLE_MAIN;
+ rtm.rtm_type = RTN_UNICAST;
+ rtm.rtm_dst_len = dst_len;
+
+ vnet_netlink_msg_init (&m, RTM_NEWROUTE,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL,
+ &rtm, sizeof (struct rtmsg));
+
+ vnet_netlink_msg_add_rtattr (&m, RTA_GATEWAY, gw, 16);
+ vnet_netlink_msg_add_rtattr (&m, RTA_DST, dst ? dst : dflt, 16);
+ return vnet_netlink_msg_send (&m);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*