ead: clean up, fix musl build

Signed-off-by: Felix Fietkau <nbd@openwrt.org>

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@45110 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Felix Fietkau 2015-03-29 04:30:05 +00:00
parent 1e80ec959a
commit 007bfd1d7d
4 changed files with 46 additions and 167 deletions

View File

@ -8,7 +8,7 @@ CONFIGURE_ARGS =
all: ead ead-client
obj = ead-crypt.o
obj = ead-crypt.o libbridge_init.o
tinysrp/Makefile:
cd tinysrp; ./configure $(CONFIGURE_ARGS)

View File

@ -30,18 +30,16 @@
#include <t_sha.h>
#include <t_defines.h>
#include <t_server.h>
#include <net/if.h>
#include "list.h"
#include "ead.h"
#include "ead-pcap.h"
#include "ead-crypt.h"
#include "libbridge.h"
#include "filter.c"
#ifdef linux
#include "libbridge_init.c"
#endif
#ifdef linux
#include <linux/if_packet.h>
#endif
@ -74,10 +72,8 @@ struct ead_instance {
char ifname[16];
int pid;
char id;
#ifdef linux
char bridge[16];
bool br_check;
#endif
};
static char ethmac[6] = "\x00\x13\x37\x00\x00\x00"; /* last 3 bytes will be randomized */
@ -696,13 +692,10 @@ ead_pcap_reopen(bool first)
pcap_fp_rx = NULL;
do {
#ifdef linux
if (instance->bridge[0]) {
pcap_fp_rx = ead_open_pcap(instance->bridge, errbuf, 1);
pcap_fp = ead_open_pcap(instance->ifname, errbuf, 0);
} else
#endif
{
} else {
pcap_fp = ead_open_pcap(instance->ifname, errbuf, 1);
}
@ -836,7 +829,6 @@ server_handle_sigint(int sig)
exit(1);
}
#ifdef linux
static int
check_bridge_port(const char *br, const char *port, void *arg)
{
@ -866,12 +858,10 @@ check_bridge(const char *name, void *arg)
br_foreach_port(name, check_bridge_port, arg);
return 0;
}
#endif
static void
check_all_interfaces(void)
{
#ifdef linux
struct ead_instance *in;
struct list_head *p;
@ -889,7 +879,6 @@ check_all_interfaces(void)
stop_server(in, false);
}
}
#endif
}
@ -973,9 +962,7 @@ int main(int argc, char **argv)
nid = *(((u16_t *) ethmac) + 2);
start_servers(false);
#ifdef linux
br_init();
#endif
tv.tv_sec = 1;
tv.tv_usec = 0;
while (1) {
@ -983,9 +970,7 @@ int main(int argc, char **argv)
start_servers(true);
sleep(1);
}
#ifdef linux
br_shutdown();
#endif
return 0;
}

View File

@ -19,67 +19,42 @@
#ifndef _LIBBRIDGE_H
#define _LIBBRIDGE_H
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/in6.h>
#include <linux/if_bridge.h>
#ifdef linux
/* defined in net/if.h but that conflicts with linux/if.h... */
extern unsigned int if_nametoindex (const char *__ifname);
extern char *if_indextoname (unsigned int __ifindex, char *__ifname);
int br_init(void);
void br_shutdown(void);
struct bridge_id
int br_foreach_port(const char *brname,
int (*iterator)(const char *br, const char *port, void *arg),
void *arg);
int br_foreach_bridge(int (*iterator)(const char *, void *), void *arg);
#else
static inline int br_init(void)
{
unsigned char prio[2];
unsigned char addr[6];
};
return 0;
}
struct bridge_info
static inline void br_shutdown(void)
{
struct bridge_id designated_root;
struct bridge_id bridge_id;
unsigned root_path_cost;
struct timeval max_age;
struct timeval hello_time;
struct timeval forward_delay;
struct timeval bridge_max_age;
struct timeval bridge_hello_time;
struct timeval bridge_forward_delay;
u_int16_t root_port;
unsigned char stp_enabled;
unsigned char topology_change;
unsigned char topology_change_detected;
struct timeval ageing_time;
struct timeval hello_timer_value;
struct timeval tcn_timer_value;
struct timeval topology_change_timer_value;
struct timeval gc_timer_value;
};
}
struct fdb_entry
static inline int
br_foreach_port(const char *brname,
int (*iterator)(const char *br, const char *port, void *arg),
void *arg)
{
u_int8_t mac_addr[6];
u_int16_t port_no;
unsigned char is_local;
struct timeval ageing_timer_value;
};
return 0;
}
struct port_info
static inline int
br_foreach_bridge(int (*iterator)(const char *, void *), void *arg)
{
unsigned port_no;
struct bridge_id designated_root;
struct bridge_id designated_bridge;
u_int16_t port_id;
u_int16_t designated_port;
u_int8_t priority;
unsigned char top_change_ack;
unsigned char config_pending;
unsigned char state;
unsigned path_cost;
unsigned designated_cost;
struct timeval message_age_timer_value;
struct timeval forward_delay_timer_value;
struct timeval hold_timer_value;
};
return 0;
}
#endif
#endif

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef linux
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -24,20 +26,24 @@
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/in6.h>
#include <linux/if_bridge.h>
#include "libbridge.h"
#include "libbridge_private.h"
int br_socket_fd = -1;
static int br_socket_fd = -1;
static int br_init(void)
int br_init(void)
{
if ((br_socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0)
return errno;
return 0;
}
static void br_shutdown(void)
void br_shutdown(void)
{
close(br_socket_fd);
br_socket_fd = -1;
@ -78,106 +84,19 @@ static int new_foreach_bridge(int (*iterator)(const char *name, void *),
return count;
}
/*
* Old interface uses ioctl
*/
static int old_foreach_bridge(int (*iterator)(const char *, void *),
void *iarg)
{
int i, ret=0, num;
char ifname[IFNAMSIZ];
int ifindices[MAX_BRIDGES];
unsigned long args[3] = { BRCTL_GET_BRIDGES,
(unsigned long)ifindices, MAX_BRIDGES };
num = ioctl(br_socket_fd, SIOCGIFBR, args);
if (num < 0) {
dprintf("Get bridge indices failed: %s\n",
strerror(errno));
return -errno;
}
for (i = 0; i < num; i++) {
if (!if_indextoname(ifindices[i], ifname)) {
dprintf("get find name for ifindex %d\n",
ifindices[i]);
return -errno;
}
++ret;
if(iterator(ifname, iarg))
break;
}
return ret;
}
/*
* Go over all bridges and call iterator function.
* if iterator returns non-zero then stop.
*/
static int br_foreach_bridge(int (*iterator)(const char *, void *),
void *arg)
int br_foreach_bridge(int (*iterator)(const char *, void *), void *arg)
{
int ret;
ret = new_foreach_bridge(iterator, arg);
if (ret <= 0)
ret = old_foreach_bridge(iterator, arg);
return ret;
}
/*
* Only used if sysfs is not available.
*/
static int old_foreach_port(const char *brname,
int (*iterator)(const char *br, const char *port,
void *arg),
void *arg)
{
int i, err, count;
struct ifreq ifr;
char ifname[IFNAMSIZ];
int ifindices[MAX_PORTS];
unsigned long args[4] = { BRCTL_GET_PORT_LIST,
(unsigned long)ifindices, MAX_PORTS, 0 };
memset(ifindices, 0, sizeof(ifindices));
strncpy(ifr.ifr_name, brname, IFNAMSIZ);
ifr.ifr_data = (char *) &args;
err = ioctl(br_socket_fd, SIOCDEVPRIVATE, &ifr);
if (err < 0) {
dprintf("list ports for bridge:'%s' failed: %s\n",
brname, strerror(errno));
return -errno;
}
count = 0;
for (i = 0; i < MAX_PORTS; i++) {
if (!ifindices[i])
continue;
if (!if_indextoname(ifindices[i], ifname)) {
dprintf("can't find name for ifindex:%d\n",
ifindices[i]);
continue;
}
++count;
if (iterator(brname, ifname, arg))
break;
}
return count;
return new_foreach_bridge(iterator, arg);
}
/*
* Iterate over all ports in bridge (using sysfs).
*/
static int br_foreach_port(const char *brname,
int br_foreach_port(const char *brname,
int (*iterator)(const char *br, const char *port, void *arg),
void *arg)
{
@ -187,8 +106,6 @@ static int br_foreach_port(const char *brname,
snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/brif", brname);
count = scandir(path, &namelist, 0, alphasort);
if (count < 0)
return old_foreach_port(brname, iterator, arg);
for (i = 0; i < count; i++) {
if (namelist[i]->d_name[0] == '.'
@ -206,3 +123,5 @@ static int br_foreach_port(const char *brname,
return count;
}
#endif