diff options
author | shemminger <shemminger> | 2004-05-28 20:38:38 +0000 |
---|---|---|
committer | shemminger <shemminger> | 2004-05-28 20:38:38 +0000 |
commit | 28c5adbc86ce120f3b266896379a70a9fb7f5de0 (patch) | |
tree | 13728d110f7f191b105f5cc7b57c66a6b709526d /libbridge | |
parent | f8eed52bc9ca6b3fc9281b16877abd5178a246bf (diff) | |
download | android_external_brctl-28c5adbc86ce120f3b266896379a70a9fb7f5de0.tar.gz android_external_brctl-28c5adbc86ce120f3b266896379a70a9fb7f5de0.tar.bz2 android_external_brctl-28c5adbc86ce120f3b266896379a70a9fb7f5de0.zip |
Fix set_port parameter values (more ifindex confustion).
Diffstat (limited to 'libbridge')
-rw-r--r-- | libbridge/libbridge_devif.c | 42 | ||||
-rw-r--r-- | libbridge/libbridge_init.c | 5 | ||||
-rw-r--r-- | libbridge/libbridge_private.h | 5 |
3 files changed, 41 insertions, 11 deletions
diff --git a/libbridge/libbridge_devif.c b/libbridge/libbridge_devif.c index 78a3b28..3efd1e4 100644 --- a/libbridge/libbridge_devif.c +++ b/libbridge/libbridge_devif.c @@ -27,8 +27,6 @@ #include "libbridge.h" #include "libbridge_private.h" -#define dprintf(fmt,arg...) - #ifdef HAVE_LIBSYSFS /* Given two two character "0a" convert it to a byte */ static unsigned char getoctet(const char *cp) @@ -392,11 +390,40 @@ int br_set_bridge_priority(const char *br, int bridge_priority) BRCTL_SET_BRIDGE_PRIORITY); } +static int nametoportindex(const char *brname, const char *ifname) +{ + int i; + int ifindex = if_nametoindex(ifname); + int ifindices[MAX_PORTS]; + unsigned long args[4] = { BRCTL_GET_PORT_LIST, + (unsigned long)ifindices, MAX_PORTS, 0 }; + struct ifreq ifr; + + if (ifindex <= 0) + goto error; + + memset(ifindices, 0, sizeof(ifindices)); + strncpy(ifr.ifr_name, brname, IFNAMSIZ); + ifr.ifr_data = (char *) &args; + + if (ioctl(br_socket_fd, SIOCDEVPRIVATE, &ifr) < 0) + goto error; + + for (i = 0; i < MAX_PORTS; i++) { + if (ifindices[i] == ifindex) + return i; + } + + dprintf("%s is not a in bridge %s\n", ifname, brname); + error: + return -1; +} + static int port_set(const char *bridge, const char *ifname, const char *name, unsigned long value, unsigned long oldcode) { - int ret; + int ret, index; #ifdef HAVE_LIBSYSFS struct sysfs_directory *sdir; @@ -417,15 +444,18 @@ static int port_set(const char *bridge, const char *ifname, sysfs_close_directory(sdir); } else #endif - { + if ( (index = nametoportindex(bridge, ifname)) < 0) + ret = index; + + else { struct ifreq ifr; - int ifindex = if_nametoindex(ifname); - unsigned long args[4] = { oldcode, ifindex, value, 0 }; + unsigned long args[4] = { oldcode, index, value, 0 }; strncpy(ifr.ifr_name, bridge, IFNAMSIZ); ifr.ifr_data = (char *) &args; ret = ioctl(br_socket_fd, SIOCDEVPRIVATE, &ifr); } + return ret < 0 ? errno : 0; } diff --git a/libbridge/libbridge_init.c b/libbridge/libbridge_init.c index 1c4aad5..a74aa5b 100644 --- a/libbridge/libbridge_init.c +++ b/libbridge/libbridge_init.c @@ -25,11 +25,6 @@ #include "libbridge.h" #include "libbridge_private.h" -#define MAX_BRIDGES 1024 -#define MAX_PORTS 1024 - -#define dprintf(fmt,arg...) - int br_socket_fd = -1; struct sysfs_class *br_class_net; diff --git a/libbridge/libbridge_private.h b/libbridge/libbridge_private.h index 57d0233..8d9ed0c 100644 --- a/libbridge/libbridge_private.h +++ b/libbridge/libbridge_private.h @@ -27,6 +27,11 @@ #include <linux/if_bridge.h> #include <asm/param.h> +#define MAX_BRIDGES 1024 +#define MAX_PORTS 1024 + +#define dprintf(fmt,arg...) + #ifdef HAVE_LIBSYSFS #include <sysfs/libsysfs.h> |