This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/3471 replace hand-coded tun_gifindex() with standard POSIX if_nametoindex() Change-Id: I738472765ab09f530dcf071455e1bb4e6fb3f6e5 --- M lib/tun.c 1 file changed, 3 insertions(+), 25 deletions(-) git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/71/3471/1 diff --git a/lib/tun.c b/lib/tun.c index 205d39a..717da88 100644 --- a/lib/tun.c +++ b/lib/tun.c @@ -89,30 +89,6 @@ n->nlmsg_len = alen + len; return 0; } - -int tun_gifindex(struct tun_t *this, __u32 * index) -{ - struct ifreq ifr; - int fd; - - memset(&ifr, '\0', sizeof(ifr)); - ifr.ifr_addr.sa_family = AF_INET; - ifr.ifr_dstaddr.sa_family = AF_INET; - ifr.ifr_netmask.sa_family = AF_INET; - strncpy(ifr.ifr_name, this->devname, IFNAMSIZ); - ifr.ifr_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */ - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed"); - } - if (ioctl(fd, SIOCGIFINDEX, &ifr)) { - SYS_ERR(DTUN, LOGL_ERROR, errno, "ioctl() failed"); - close(fd); - return -1; - } - close(fd); - *index = ifr.ifr_ifindex; - return 0; -} #endif int tun_sifflags(struct tun_t *this, int flags) @@ -266,7 +242,9 @@ req.i.ifa_prefixlen = 32; /* 32 FOR IPv4 */ req.i.ifa_flags = 0; req.i.ifa_scope = RT_SCOPE_HOST; /* TODO or 0 */ - if (tun_gifindex(this, &req.i.ifa_index)) { + req.i.ifa_index = if_nametoindex(this->devname); + if (!req.i.ifa_index) { + SYS_ERR(DTUN, LOGL_ERROR, errno, "Unable to get ifindex for %s", this->devname); return -1; } -- To view, visit https://gerrit.osmocom.org/3471 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I738472765ab09f530dcf071455e1bb4e6fb3f6e5 Gerrit-PatchSet: 1 Gerrit-Project: openggsn Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org>