Skip to content

Commit

Permalink
Set interface name under /proc for non kernel devices
Browse files Browse the repository at this point in the history
  • Loading branch information
cardigliano committed Dec 24, 2024
1 parent 90a13af commit b9ddfd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
13 changes: 9 additions & 4 deletions userland/lib/pfring.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ pfring *pfring_open(const char *device_name, u_int32_t caplen, u_int32_t flags)
}

/* default */
if(!mod_found) {
if(mod_found) {
pfring_set_bound_dev_name(ring, ring->device_name);
} else {
ring->device_name = strdup(device_name ? device_name : "any");
if (ring->device_name == NULL) {
errno = ENOMEM;
Expand Down Expand Up @@ -1487,10 +1489,13 @@ int pfring_recv_chunk(pfring *ring, void **chunk, pfring_chunk_info *chunk_info,
/* **************************************************** */

int pfring_set_bound_dev_name(pfring *ring, char *custom_dev_name) {
if(ring && ring->set_bound_dev_name)
return(ring->set_bound_dev_name(ring, custom_dev_name));
if(!ring)
return(PF_RING_ERROR_INVALID_ARGUMENT);

return(PF_RING_ERROR_NOT_SUPPORTED);
/* Note: set_bound_dev_name is defined by pfring_mod only
* All other modules should use it (the pf_ring socket is always created) */

return pfring_mod_set_bound_dev_name(ring, custom_dev_name);
}

/* **************************************************** */
Expand Down
1 change: 0 additions & 1 deletion userland/lib/pfring.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ struct __pfring {
int (*recv_chunk) (pfring *, void **, pfring_chunk_info *, u_int8_t);
int (*recv_burst) (pfring *, pfring_packet_info *, u_int8_t, u_int8_t);
int (*recv_flow) (pfring *, pfring_flow_update *, u_int8_t);
int (*set_bound_dev_name) (pfring *, char *);
int (*get_metadata) (pfring *, u_char **, u_int32_t *);
u_int32_t (*get_interface_speed) (pfring *);
int (*get_link_type) (pfring *);
Expand Down
8 changes: 5 additions & 3 deletions userland/lib/pfring_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ int pfring_mod_open(pfring *ring) {
ring->remove_bpf_filter = pfring_mod_remove_bpf_filter;
ring->shutdown = pfring_mod_shutdown;
ring->send_last_rx_packet = pfring_mod_send_last_rx_packet;
ring->set_bound_dev_name = pfring_mod_set_bound_dev_name;
ring->get_interface_speed = pfring_mod_get_interface_speed;

ring->poll_duration = DEFAULT_POLL_DURATION;
Expand Down Expand Up @@ -1056,8 +1055,11 @@ void pfring_mod_shutdown(pfring *ring) {
/* **************************************************** */

int pfring_mod_set_bound_dev_name(pfring *ring, char *custom_dev_name) {
return(setsockopt(ring->fd, 0, SO_SET_CUSTOM_BOUND_DEV_NAME,
custom_dev_name, strlen(custom_dev_name)));
if (!custom_dev_name)
return PF_RING_ERROR_INVALID_ARGUMENT;

return(setsockopt(ring->fd, 0, SO_SET_CUSTOM_BOUND_DEV_NAME,
custom_dev_name, strlen(custom_dev_name)));
}

/* *************************************** */
Expand Down

0 comments on commit b9ddfd5

Please sign in to comment.