git: 157bf2c9964a - stable/13 - ifconfig: improve vlan options parsing

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Mon, 28 Mar 2022 09:16:07 UTC
The branch stable/13 has been updated by melifaro:

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

commit 157bf2c9964a54124e05bb7c354d8e5ad784802a
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-01-17 09:30:26 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2022-03-28 08:50:12 +0000

    ifconfig: improve vlan options parsing
    
    PR:     261136
    Reported by:    Daniel O'Connor
    MFC after:      2 weeks
    
    (cherry picked from commit 779fd05344662aeec79c29470258bf657318eab3)
---
 sbin/ifconfig/ifvlan.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/sbin/ifconfig/ifvlan.c b/sbin/ifconfig/ifvlan.c
index 60f97338ee27..1e74b504fc26 100644
--- a/sbin/ifconfig/ifvlan.c
+++ b/sbin/ifconfig/ifvlan.c
@@ -126,11 +126,6 @@ vlan_parse_ethervid(const char *name)
 	strlcpy(ifname, name, IFNAMSIZ);
 	if ((cp = strrchr(ifname, '.')) == NULL)
 		return;
-	/*
-	 * Don't mix vlan/vlandev parameters with dot notation.
-	 */
-	if (params.vlr_tag != NOTAG || params.vlr_parent[0] != '\0')
-		errx(1, "ambiguous vlan specification");
 	/*
 	 * Derive params from interface name: "parent.vid".
 	 */
@@ -144,8 +139,20 @@ vlan_parse_ethervid(const char *name)
 	if ((*cp != '\0') || (vid & ~0xFFF))
 		errx(1, "invalid vlan tag");
 
-	strlcpy(params.vlr_parent, ifname, IFNAMSIZ);
-	params.vlr_tag = (vid & 0xFFF);
+	/*
+	 * allow "devX.Y vlandev devX vlan Y" syntax
+	 */
+	if (params.vlr_tag == NOTAG || params.vlr_tag == vid)
+		params.vlr_tag = vid;
+	else
+		errx(1, "ambiguous vlan specification");
+
+	/* Restrict overriding interface name */
+	if (params.vlr_parent[0] == '\0' || !strcmp(params.vlr_parent, ifname))
+		strlcpy(params.vlr_parent, ifname, IFNAMSIZ);
+	else
+		errx(1, "ambiguous vlan specification");
+	printf("CR: %s %d\n", params.vlr_parent, params.vlr_tag);
 }
 
 static void