[PATCH 1/1] fixup! Add VRF support

Thomas Haller thaller at redhat.com
Fri Oct 23 08:03:10 PDT 2015


---

 If you'd agree, I'd add the following changes.

 - no TABs after first indention.

 - have same whitespace in our kernel header copy
   as upstream kernel (to have smaller diff).

 - sort entries in .sym file by name.

 - make vrf_alloc properly handle cases where the
   data is already allocated.


 include/linux-private/linux/if_link.h |  6 +++---
 lib/route/link/vrf.c                  | 27 +++++++++++++++------------
 libnl-route-3.sym                     |  3 +--
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/include/linux-private/linux/if_link.h b/include/linux-private/linux/if_link.h
index f8eb94a..af4a8f9 100644
--- a/include/linux-private/linux/if_link.h
+++ b/include/linux-private/linux/if_link.h
@@ -339,9 +339,9 @@ enum macvlan_macaddr_mode {
 
 /* VRF section */
 enum {
-        IFLA_VRF_UNSPEC,
-        IFLA_VRF_TABLE,
-        __IFLA_VRF_MAX
+	IFLA_VRF_UNSPEC,
+	IFLA_VRF_TABLE,
+	__IFLA_VRF_MAX
 };
 
 #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1)
diff --git a/lib/route/link/vrf.c b/lib/route/link/vrf.c
index 055eb4c..84d2d8b 100644
--- a/lib/route/link/vrf.c
+++ b/lib/route/link/vrf.c
@@ -41,8 +41,8 @@
 #define VRF_HAS_TABLE_ID    (1<<0)
 
 struct vrf_info {
-	uint32_t	table_id;
-	uint32_t	vi_mask;
+	uint32_t        table_id;
+	uint32_t        vi_mask;
 };
 
 /** @endcond */
@@ -55,6 +55,11 @@ static int vrf_alloc(struct rtnl_link *link)
 {
 	struct vrf_info *vi;
 
+	if (link->l_info) {
+		memset(link->l_info, 0, sizeof (*vi));
+		return 0;
+	}
+
 	if ((vi = calloc(1, sizeof(*vi))) == NULL)
 		return -NLE_NOMEM;
 
@@ -102,13 +107,11 @@ static int vrf_clone(struct rtnl_link *dst, struct rtnl_link *src)
 	struct vrf_info *vdst, *vsrc = src->l_info;
 	int err;
 
-	dst->l_info = NULL;
 	if ((err = rtnl_link_set_type(dst, "vrf")) < 0)
 		return err;
 	vdst = dst->l_info;
 
-	if (!vdst || !vsrc)
-		return -NLE_NOMEM;
+	BUG_ON(!vdst || !vsrc);
 
 	memcpy(vdst, vsrc, sizeof(struct vrf_info));
 
@@ -121,7 +124,7 @@ static int vrf_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
 	struct nlattr *data;
 
 	if (!(data = nla_nest_start(msg, IFLA_INFO_DATA)))
-		return -NLE_MSGSIZE;
+		return -NLE_NOMEM;
 
 	if (vi->vi_mask & VRF_HAS_TABLE_ID) {
 		NLA_PUT_U32(msg, IFLA_VRF_TABLE, vi->table_id);
@@ -144,16 +147,16 @@ static void vrf_dump(struct rtnl_link *link, struct nl_dump_params *p)
 }
 
 static struct rtnl_link_info_ops vrf_info_ops = {
-	.io_name		= "vrf",
-	.io_alloc		= vrf_alloc,
-	.io_parse		= vrf_parse,
+	.io_name                = "vrf",
+	.io_alloc               = vrf_alloc,
+	.io_parse               = vrf_parse,
 	.io_dump = {
 		[NL_DUMP_LINE]     = vrf_dump,
 		[NL_DUMP_DETAILS]  = vrf_dump,
 	},
-	.io_clone		= vrf_clone,
-	.io_put_attrs		= vrf_put_attrs,
-	.io_free		= vrf_free,
+	.io_clone               = vrf_clone,
+	.io_put_attrs           = vrf_put_attrs,
+	.io_free                = vrf_free,
 };
 
 /** @cond SKIP */
diff --git a/libnl-route-3.sym b/libnl-route-3.sym
index 0502e45..23b839a 100644
--- a/libnl-route-3.sym
+++ b/libnl-route-3.sym
@@ -885,11 +885,10 @@ global:
 	rtnl_link_set_link_netnsid;
 } libnl_3_2_26;
 
-
 libnl_3_2_28 {
 global:
-	rtnl_link_vrf_alloc;
 	rtnl_link_is_vrf;
+	rtnl_link_vrf_alloc;
 	rtnl_link_vrf_get_tableid;
 	rtnl_link_vrf_set_tableid;
 } libnl_3_2_27;
-- 
2.4.3




More information about the libnl mailing list