Browse Source

1

nodeinfo-routing-update
Evgeny 7 months ago
parent
commit
ea9d6d8870
  1. 30
      src/tun_freebsd.c

30
src/tun_freebsd.c

@ -117,22 +117,22 @@ static int tun_set_ip(const char *ifname, const char *ip_addr) {
return 0;
}
// Bring TUN interface up
// Bring TUN interface up (using ifconfig - more reliable on FreeBSD)
static int tun_set_up(const char *ifname) {
if (!ifname) {
errno = EINVAL;
return -1;
}
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
// Get current flags
if (if_ioctl(ifname, SIOCGIFFLAGS, &ifr) < 0) return -1;
// Set UP and RUNNING
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (if_ioctl(ifname, SIOCSIFFLAGS, &ifr) < 0) return -1;
// Use ifconfig to bring up the interface
char cmd[256];
snprintf(cmd, sizeof(cmd), "ifconfig %s up 2>/dev/null", ifname);
int ret = system(cmd);
if (ret != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "ifconfig %s up failed", ifname);
return -1;
}
return 0;
}
@ -164,15 +164,7 @@ int tun_platform_init(struct tun_if* tun, const char* ifname, const char* ip_str
return -1;
}
// Bring interface UP first (required before setting IP on FreeBSD)
if (tun_set_up(tun->ifname) < 0) {
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "Failed to bring up TUN interface %s", tun->ifname);
close(tun->fd);
tun->fd = -1;
return -1;
}
// Configure IP address using ifconfig
// Configure IP address using ifconfig (also brings up the interface)
if (tun_set_ip(tun->ifname, ip_str) < 0) {
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "Failed to set TUN IP: %s", ip_str);
close(tun->fd);

Loading…
Cancel
Save