1e5b75505Sopenharmony_ci/* 2e5b75505Sopenharmony_ci * hostapd / VLAN ifconfig helpers 3e5b75505Sopenharmony_ci * Copyright 2003, Instant802 Networks, Inc. 4e5b75505Sopenharmony_ci * Copyright 2005-2006, Devicescape Software, Inc. 5e5b75505Sopenharmony_ci * Copyright (c) 2009, Jouni Malinen <j@w1.fi> 6e5b75505Sopenharmony_ci * 7e5b75505Sopenharmony_ci * This software may be distributed under the terms of the BSD license. 8e5b75505Sopenharmony_ci * See README for more details. 9e5b75505Sopenharmony_ci */ 10e5b75505Sopenharmony_ci 11e5b75505Sopenharmony_ci#include "utils/includes.h" 12e5b75505Sopenharmony_ci#include <net/if.h> 13e5b75505Sopenharmony_ci#include <sys/ioctl.h> 14e5b75505Sopenharmony_ci 15e5b75505Sopenharmony_ci#include "utils/common.h" 16e5b75505Sopenharmony_ci#include "vlan_util.h" 17e5b75505Sopenharmony_ci 18e5b75505Sopenharmony_ci 19e5b75505Sopenharmony_ciint ifconfig_helper(const char *if_name, int up) 20e5b75505Sopenharmony_ci{ 21e5b75505Sopenharmony_ci int fd; 22e5b75505Sopenharmony_ci struct ifreq ifr; 23e5b75505Sopenharmony_ci 24e5b75505Sopenharmony_ci if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { 25e5b75505Sopenharmony_ci wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) " 26e5b75505Sopenharmony_ci "failed: %s", __func__, strerror(errno)); 27e5b75505Sopenharmony_ci return -1; 28e5b75505Sopenharmony_ci } 29e5b75505Sopenharmony_ci 30e5b75505Sopenharmony_ci os_memset(&ifr, 0, sizeof(ifr)); 31e5b75505Sopenharmony_ci os_strlcpy(ifr.ifr_name, if_name, IFNAMSIZ); 32e5b75505Sopenharmony_ci 33e5b75505Sopenharmony_ci if (ioctl(fd, SIOCGIFFLAGS, &ifr) != 0) { 34e5b75505Sopenharmony_ci wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCGIFFLAGS) failed " 35e5b75505Sopenharmony_ci "for interface %s: %s", 36e5b75505Sopenharmony_ci __func__, if_name, strerror(errno)); 37e5b75505Sopenharmony_ci close(fd); 38e5b75505Sopenharmony_ci return -1; 39e5b75505Sopenharmony_ci } 40e5b75505Sopenharmony_ci 41e5b75505Sopenharmony_ci if (up) 42e5b75505Sopenharmony_ci ifr.ifr_flags |= IFF_UP; 43e5b75505Sopenharmony_ci else 44e5b75505Sopenharmony_ci ifr.ifr_flags &= ~IFF_UP; 45e5b75505Sopenharmony_ci 46e5b75505Sopenharmony_ci if (ioctl(fd, SIOCSIFFLAGS, &ifr) != 0) { 47e5b75505Sopenharmony_ci wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCSIFFLAGS) failed " 48e5b75505Sopenharmony_ci "for interface %s (up=%d): %s", 49e5b75505Sopenharmony_ci __func__, if_name, up, strerror(errno)); 50e5b75505Sopenharmony_ci close(fd); 51e5b75505Sopenharmony_ci return -1; 52e5b75505Sopenharmony_ci } 53e5b75505Sopenharmony_ci 54e5b75505Sopenharmony_ci close(fd); 55e5b75505Sopenharmony_ci return 0; 56e5b75505Sopenharmony_ci} 57e5b75505Sopenharmony_ci 58e5b75505Sopenharmony_ci 59e5b75505Sopenharmony_ciint ifconfig_up(const char *if_name) 60e5b75505Sopenharmony_ci{ 61e5b75505Sopenharmony_ci wpa_printf(MSG_DEBUG, "VLAN: Set interface %s up", if_name); 62e5b75505Sopenharmony_ci return ifconfig_helper(if_name, 1); 63e5b75505Sopenharmony_ci} 64e5b75505Sopenharmony_ci 65e5b75505Sopenharmony_ci 66e5b75505Sopenharmony_ciint iface_exists(const char *ifname) 67e5b75505Sopenharmony_ci{ 68e5b75505Sopenharmony_ci return if_nametoindex(ifname); 69e5b75505Sopenharmony_ci} 70