Skip to content

Commit 6c4260b

Browse files
committed
virnetlink: Split virNetlinkBridgeVlanFilterSet()
Currently, virNetlinkBridgeVlanFilterSet() takes @cmd as the second argument where either RTM_SETLINK or RTM_DELLINK is expected. Both of these constants come from linux/rtnetlink.h and thus are undefined when building without netlink. This design also clashes with the whole point of virnetlink: to offload netlink dependency onto a single file. Therefore, drop the argument, turn virNetlinkBridgeVlanFilterSet() into just setter, effectively, and introduce virNetlinkBridgeVlanFilterDel() for the case when RTM_DELLINK would be passed as @cmd. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/770 Signed-off-by: Michal Privoznik <[email protected]> Reviewed-by: Peter Krempa <[email protected]>
1 parent 6a23a61 commit 6c4260b

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

src/util/virnetdevbridge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ virNetDevBridgeSetupVlans(const char *ifname, const virNetDevVlan *virtVlan)
321321
return 0;
322322

323323
/* The interface will have been automatically added to vlan 1, so remove it. */
324-
if (virNetlinkBridgeVlanFilterSet(ifname, RTM_DELLINK, 0, 1, &error) < 0) {
324+
if (virNetlinkBridgeVlanFilterDel(ifname, 1, &error) < 0) {
325325
if (error != 0) {
326326
virReportSystemError(-error,
327327
_("error removing vlan filter from interface %1$s"),
@@ -341,23 +341,23 @@ virNetDevBridgeSetupVlans(const char *ifname, const virNetDevVlan *virtVlan)
341341
flags |= BRIDGE_VLAN_INFO_UNTAGGED;
342342
}
343343

344-
if (virNetlinkBridgeVlanFilterSet(ifname, RTM_SETLINK, flags,
344+
if (virNetlinkBridgeVlanFilterSet(ifname, flags,
345345
virtVlan->nativeTag, &error) < 0) {
346346
goto error;
347347
}
348348
}
349349

350350
for (i = 0; i < virtVlan->nTags; i++) {
351351
if (virtVlan->tag[i] != virtVlan->nativeTag)
352-
if (virNetlinkBridgeVlanFilterSet(ifname, RTM_SETLINK, 0,
352+
if (virNetlinkBridgeVlanFilterSet(ifname, 0,
353353
virtVlan->tag[i], &error) < 0) {
354354
goto error;
355355
}
356356
}
357357
} else {
358358
/* In native mode, add the single VLAN as pvid untagged. */
359359
flags = BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED;
360-
if (virNetlinkBridgeVlanFilterSet(ifname, RTM_SETLINK, flags,
360+
if (virNetlinkBridgeVlanFilterSet(ifname, flags,
361361
virtVlan->tag[0], &error) < 0) {
362362
goto error;
363363
}

src/util/virnetlink.c

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ virNetlinkDelLink(const char *ifname, virNetlinkTalkFallback fallback)
702702
}
703703

704704
/**
705-
* virNetlinkBridgeVlanFilterSet:
705+
* virNetlinkBridgeVlanFilterHelper:
706706
*
707707
* @ifname: name of the link
708708
* @cmd: netlink command, either RTM_SETLINK or RTM_DELLINK
@@ -717,12 +717,12 @@ virNetlinkDelLink(const char *ifname, virNetlinkTalkFallback fallback)
717717
* non-zero, then a netlink failure occurred, but no error message
718718
* is generated leaving it up to the caller to handle the condition.
719719
*/
720-
int
721-
virNetlinkBridgeVlanFilterSet(const char *ifname,
722-
int cmd,
723-
const unsigned short flags,
724-
const short vid,
725-
int *error)
720+
static int
721+
virNetlinkBridgeVlanFilterHelper(const char *ifname,
722+
int cmd,
723+
const unsigned short flags,
724+
const short vid,
725+
int *error)
726726
{
727727
struct ifinfomsg ifm = { .ifi_family = PF_BRIDGE };
728728
struct bridge_vlan_info vinfo = { .flags = flags, .vid = vid };
@@ -767,6 +767,55 @@ virNetlinkBridgeVlanFilterSet(const char *ifname,
767767
return 0;
768768
}
769769

770+
771+
/**
772+
* virNetlinkBridgeVlanFilterSet:
773+
*
774+
* @ifname: name of the link
775+
* @flags: flags to use when adding the vlan filter
776+
* @vid: vlan id to add
777+
* @error: netlink error code
778+
*
779+
* Add a vlan filter from an interface associated with a bridge.
780+
*
781+
* Returns 0 on success, -1 on error. Additionally, if the @error is
782+
* non-zero, then a netlink failure occurred, but no error message
783+
* is generated leaving it up to the caller to handle the condition.
784+
*/
785+
int
786+
virNetlinkBridgeVlanFilterSet(const char *ifname,
787+
const unsigned short flags,
788+
const short vid,
789+
int *error)
790+
{
791+
return virNetlinkBridgeVlanFilterHelper(ifname, RTM_SETLINK,
792+
flags, vid, error);
793+
}
794+
795+
796+
/**
797+
* virNetlinkBridgeVlanFilterDel:
798+
*
799+
* @ifname: name of the link
800+
* @vid: vlan id to remove
801+
* @error: netlink error code
802+
*
803+
* Remove a vlan filter from an interface associated with a bridge.
804+
*
805+
* Returns 0 on success, -1 on error. Additionally, if the @error is
806+
* non-zero, then a netlink failure occurred, but no error message
807+
* is generated leaving it up to the caller to handle the condition.
808+
*/
809+
int
810+
virNetlinkBridgeVlanFilterDel(const char *ifname,
811+
const short vid,
812+
int *error)
813+
{
814+
return virNetlinkBridgeVlanFilterHelper(ifname,
815+
RTM_DELLINK, 0, vid, error);
816+
}
817+
818+
770819
/**
771820
* virNetlinkGetNeighbor:
772821
*
@@ -1346,7 +1395,6 @@ virNetlinkNewLink(const char *ifname G_GNUC_UNUSED,
13461395

13471396
int
13481397
virNetlinkBridgeVlanFilterSet(const char *ifname G_GNUC_UNUSED,
1349-
int cmd G_GNUC_UNUSED,
13501398
const unsigned short unusedflags G_GNUC_UNUSED,
13511399
const short vid G_GNUC_UNUSED,
13521400
int *error)
@@ -1356,6 +1404,15 @@ virNetlinkBridgeVlanFilterSet(const char *ifname G_GNUC_UNUSED,
13561404
return -1;
13571405
}
13581406

1407+
int
1408+
virNetlinkBridgeVlanFilterDel(const char *ifname G_GNUC_UNUSED,
1409+
const short vid G_GNUC_UNUSED,
1410+
int *error G_GNUC_UNUSED)
1411+
{
1412+
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
1413+
return -1;
1414+
}
1415+
13591416
int
13601417
virNetlinkGetNeighbor(void **nlData G_GNUC_UNUSED,
13611418
uint32_t src_pid G_GNUC_UNUSED,

src/util/virnetlink.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ typedef int (*virNetlinkTalkFallback)(const char *ifname);
7878
int virNetlinkDelLink(const char *ifname, virNetlinkTalkFallback fallback);
7979

8080
int virNetlinkBridgeVlanFilterSet(const char *ifname,
81-
int cmd,
8281
const unsigned short flags,
8382
const short vid,
8483
int *error);
8584

85+
int virNetlinkBridgeVlanFilterDel(const char *ifname,
86+
const short vid,
87+
int *error);
88+
8689
int virNetlinkGetErrorCode(struct nlmsghdr *resp, unsigned int recvbuflen);
8790

8891
int virNetlinkDumpLink(const char *ifname, int ifindex,

0 commit comments

Comments
 (0)