diff options
author | Simon Chopin <s.chopin@alphalink.fr> | 2020-02-28 11:28:07 +0100 |
---|---|---|
committer | Simon Chopin <s.chopin@alphalink.fr> | 2020-03-18 09:07:38 +0100 |
commit | f5b1c3f98bf082d4ecf57e8f2e3c61fc993d80e7 (patch) | |
tree | 060169e9c70a15cc083d4efbbe52a9537264dfd3 /accel-pppd/net.c | |
parent | 7afe0f075676219ab4b9e8dbfed294992e9f360b (diff) | |
download | accel-ppp-f5b1c3f98bf082d4ecf57e8f2e3c61fc993d80e7.tar.gz accel-ppp-f5b1c3f98bf082d4ecf57e8f2e3c61fc993d80e7.zip |
net: new function get_ifindex
The index of a given interface is an operation that highly depends on
the network namespace we're in. This patch simply cuts out a function to
get the index for a given interface name from the session initialization
code, and expose it in the ap_net structure.
This function can then be used to refresh the index when moving
interfaces around.
Signed-off-by: Simon Chopin <s.chopin@alphalink.fr>
Diffstat (limited to 'accel-pppd/net.c')
-rw-r--r-- | accel-pppd/net.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/accel-pppd/net.c b/accel-pppd/net.c index e5cf2818..9a025ed3 100644 --- a/accel-pppd/net.c +++ b/accel-pppd/net.c @@ -7,6 +7,7 @@ #include <sched.h> #include <limits.h> #include <errno.h> +#include <linux/if.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/syscall.h> @@ -215,6 +216,22 @@ static int def_move_link(struct ap_net *new_net, int ifindex) #endif } +static int def_get_ifindex(const char *ifname) +{ + struct kern_net *n = container_of(net, typeof(*n), net); + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, ifname); + + if (ioctl(n->sock, SIOCGIFINDEX, &ifr)) { + log_ppp_error("ioctl(SIOCGIFINDEX): %s\n", strerror(errno)); + return -1; + } + return ifr.ifr_ifindex; +} + + static void def_release(struct ap_net *d) { struct kern_net *n = container_of(d, typeof(*n), net); @@ -299,6 +316,7 @@ static struct ap_net *alloc_net(const char *name) net->rtnl_put = def_rtnl_put; net->rtnl_open = def_rtnl_open; net->move_link = def_move_link; + net->get_ifindex = def_get_ifindex; net->release = def_release; n->sock = socket(AF_INET, SOCK_DGRAM, 0); |