summaryrefslogtreecommitdiffstats
path: root/src/plugins/af_packet/device.c
diff options
context:
space:
mode:
authorMohsin Kazmi <sykazmi@cisco.com>2023-03-07 11:07:56 +0000
committerDamjan Marion <dmarion@0xa5.net>2023-03-10 15:54:22 +0000
commit7b0d48fbb3ceebcafb18177fba02ab1a9ad4c24e (patch)
tree470661b8958c8eb70a452d93ea307b53c18eb642 /src/plugins/af_packet/device.c
parent66c675e1a514a85ac56faf686fb96b63505c994f (diff)
af_packet: fix the broken functionality upon admin down
Type: fix In vpp, file descriptor handler closes the fd upon error if there is no error handling function is registered. This patch fixes the issue for af_packet interface by registering the error handling function. Errors will also be gracefully logged. Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com> Change-Id: I260d780ac54ffd0199dcd6ca5b95e5afe957e968
Diffstat (limited to 'src/plugins/af_packet/device.c')
-rw-r--r--src/plugins/af_packet/device.c45
1 files changed, 4 insertions, 41 deletions
diff --git a/src/plugins/af_packet/device.c b/src/plugins/af_packet/device.c
index 27f5559c8cd..fc6733fc446 100644
--- a/src/plugins/af_packet/device.c
+++ b/src/plugins/af_packet/device.c
@@ -35,6 +35,7 @@
#include <af_packet/af_packet.h>
#include <vnet/devices/virtio/virtio_std.h>
+#include <vnet/devices/netlink.h>
#define foreach_af_packet_tx_func_error \
_(FRAME_NOT_READY, "tx frame not ready") \
@@ -654,63 +655,25 @@ af_packet_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
af_packet_if_t *apif =
pool_elt_at_index (apm->interfaces, hw->dev_instance);
u32 hw_flags;
- int rv, fd = socket (AF_UNIX, SOCK_DGRAM, 0);
- struct ifreq ifr;
-
- if (0 > fd)
- {
- vlib_log_warn (apm->log_class, "af_packet_%s could not open socket",
- apif->host_if_name);
- return 0;
- }
- /* if interface is a bridge ignore */
if (apif->host_if_index < 0)
- goto error; /* no error */
-
- /* use host_if_index in case host name has changed */
- ifr.ifr_ifindex = apif->host_if_index;
- if ((rv = ioctl (fd, SIOCGIFNAME, &ifr)) < 0)
- {
- vlib_log_warn (apm->log_class,
- "af_packet_%s ioctl could not retrieve eth name",
- apif->host_if_name);
- goto error;
- }
+ return 0; /* no error */
apif->is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
- if ((rv = ioctl (fd, SIOCGIFFLAGS, &ifr)) < 0)
- {
- vlib_log_warn (apm->log_class, "af_packet_%s error: %d",
- apif->is_admin_up ? "up" : "down", rv);
- goto error;
- }
-
if (apif->is_admin_up)
{
hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP;
- ifr.ifr_flags |= IFF_UP;
+ vnet_netlink_set_link_state (apif->host_if_index, 1);
}
else
{
hw_flags = 0;
- ifr.ifr_flags &= ~IFF_UP;
- }
-
- if ((rv = ioctl (fd, SIOCSIFFLAGS, &ifr)) < 0)
- {
- vlib_log_warn (apm->log_class, "af_packet_%s error: %d",
- apif->is_admin_up ? "up" : "down", rv);
- goto error;
+ vnet_netlink_set_link_state (apif->host_if_index, 0);
}
vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
-error:
- if (0 <= fd)
- close (fd);
-
return 0; /* no error */
}