ifconfig: fix vlan/vlanproto reconfiguration

The setvlantag() and setvlanproto() functions are used in two scenarios:
when we create a new vlan interface and when we update an existing
interface.
These are distinguished by the getvlan() at the end of the functions. If
this fails we assume that is because the interface doesn't exist (so
we're creating a new one). We only update the 'params' struct, and
expect the settings to be applied when we vlan_create().

However, if we're updating an existing interface we do not retrieve the
current settings, and can end up invalidating settings.

Fix this by using the settings we retrieved while checking which
scenario we're in.

Note that we do not address this for setvlandev(), because if_vlan does
not allow the vlan parent device to be changed without disassociating it
first (with ifconfig vlanX -vlandev).

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D35848
This commit is contained in:
Kristof Provost 2022-07-19 00:25:56 +02:00
parent 663f556b03
commit b82b8055ad

View File

@ -204,8 +204,11 @@ DECL_CMD_FUNC(setvlantag, val, d)
if (params.vlr_tag != ul)
errx(1, "value for vlan out of range");
if (getvlan(s, &ifr, &vreq) != -1)
if (getvlan(s, &ifr, &vreq) != -1) {
vreq.vlr_tag = params.vlr_tag;
memcpy(&params, &vreq, sizeof(params));
vlan_set(s, &ifr);
}
}
static
@ -233,8 +236,11 @@ DECL_CMD_FUNC(setvlanproto, val, d)
} else
errx(1, "invalid value for vlanproto");
if (getvlan(s, &ifr, &vreq) != -1)
if (getvlan(s, &ifr, &vreq) != -1) {
vreq.vlr_proto = params.vlr_proto;
memcpy(&params, &vreq, sizeof(params));
vlan_set(s, &ifr);
}
}
static