git: ce9f95bd835e - main - netlink: fix vlan interface creation

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Fri, 03 Mar 2023 16:02:24 UTC
The branch main has been updated by melifaro:

URL: https://cgit.FreeBSD.org/src/commit/?id=ce9f95bd835ec7d3ac6def5a910282509b1413f0

commit ce9f95bd835ec7d3ac6def5a910282509b1413f0
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2023-03-03 16:01:34 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-03-03 16:02:05 +0000

    netlink: fix vlan interface creation
    
    MFC after:      2 weeks
---
 sys/netlink/route/iface_drivers.c    | 34 +++++++++++++++++++---------------
 tests/sys/netlink/test_rtnl_iface.py |  1 -
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/sys/netlink/route/iface_drivers.c b/sys/netlink/route/iface_drivers.c
index 7cfaa5a6614b..be28a0f3b676 100644
--- a/sys/netlink/route/iface_drivers.c
+++ b/sys/netlink/route/iface_drivers.c
@@ -144,20 +144,14 @@ store_cookie(struct nl_pstate *npt, struct ifnet *ifp)
 	nlmsg_report_cookie(npt, nla_cookie);
 }
 
-/*
- * Generic creation interface handler.
- * Responsible for creating interfaces w/o parameters and setting
- * misc attributes such as state, mtu or description.
- */
 static int
-create_generic(struct nl_parsed_link *lattrs, const struct nlattr_bmask *bm,
-    struct nlpcb *nlp, struct nl_pstate *npt)
+create_generic_ifd(struct nl_parsed_link *lattrs, const struct nlattr_bmask *bm,
+    struct ifc_data *ifd, struct nlpcb *nlp, struct nl_pstate *npt)
 {
 	int error = 0;
 
-	struct ifc_data ifd = {};
 	struct ifnet *ifp = NULL;
-	error = ifc_create_ifp(lattrs->ifla_ifname, &ifd, &ifp);
+	error = ifc_create_ifp(lattrs->ifla_ifname, ifd, &ifp);
 
 	NLP_LOG(LOG_DEBUG2, nlp, "clone for %s returned %d", lattrs->ifla_ifname, error);
 
@@ -177,6 +171,19 @@ create_generic(struct nl_parsed_link *lattrs, const struct nlattr_bmask *bm,
 
 	return (error);
 }
+/*
+ * Generic creation interface handler.
+ * Responsible for creating interfaces w/o parameters and setting
+ * misc attributes such as state, mtu or description.
+ */
+static int
+create_generic(struct nl_parsed_link *lattrs, const struct nlattr_bmask *bm,
+    struct nlpcb *nlp, struct nl_pstate *npt)
+{
+	struct ifc_data ifd = {};
+
+	return (create_generic_ifd(lattrs, bm, &ifd, nlp, npt));
+}
 
 struct nl_cloner generic_cloner = {
 	.name = "_default_",
@@ -258,17 +265,14 @@ create_vlan(struct nl_parsed_link *lattrs, const struct nlattr_bmask *bm,
 		return (ENOENT);
 	}
 
-	/* Waiting till if_clone changes lands */
-/*
 	struct vlanreq params = {
 		.vlr_tag = attrs.vlan_id,
 		.vlr_proto = attrs.vlan_proto,
 	};
-*/
-	int ifname_len = strlen(lattrs->ifla_ifname) + 1;
-	error = if_clone_create(lattrs->ifla_ifname, ifname_len, (char *)NULL);
+	strlcpy(params.vlr_parent, if_name(ifp), sizeof(params.vlr_parent));
+	struct ifc_data ifd = { .flags = IFC_F_SYSSPACE, .params = &params };
 
-	NLP_LOG(LOG_DEBUG2, nlp, "clone for %s returned %d", lattrs->ifla_ifname, error);
+	error = create_generic_ifd(lattrs, bm, &ifd, nlp, npt);
 
 	if_rele(ifp);
 	return (error);
diff --git a/tests/sys/netlink/test_rtnl_iface.py b/tests/sys/netlink/test_rtnl_iface.py
index 35015ea2ec6e..da3db93b05c6 100644
--- a/tests/sys/netlink/test_rtnl_iface.py
+++ b/tests/sys/netlink/test_rtnl_iface.py
@@ -313,7 +313,6 @@ class TestRtNlIface(NetlinkTestTemplate, SingleVnetTestTemplate):
     # *      {{nla_len=8, nla_type=IFLA_INFO_KIND}, "vlan"...},
     # *      {{nla_len=12, nla_type=IFLA_INFO_DATA}, "\x06\x00\x01\x00\x16\x00\x00\x00"}
     # */
-    @pytest.mark.skip(reason="vlan support needs more work")
     @pytest.mark.require_user("root")
     def test_create_vlan_plain(self):
         """Creates 802.1Q VLAN interface in vlanXX and ifX fashion"""