Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifbridge.c
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <libifconfig.h> | |||||
#include "ifconfig.h" | #include "ifconfig.h" | ||||
static const char *stpstates[] = { STP_STATES }; | static const char *stpstates[] = { STP_STATES }; | ||||
static const char *stpproto[] = { STP_PROTOS }; | static const char *stpproto[] = { STP_PROTOS }; | ||||
static const char *stproles[] = { STP_ROLES }; | static const char *stproles[] = { STP_ROLES }; | ||||
static int | static int | ||||
get_val(const char *cp, u_long *valp) | get_val(const char *cp, u_long *valp) | ||||
Show All 40 Lines | do_bridgeflag(int sock, const char *ifs, int flag, int set) | ||||
else | else | ||||
req.ifbr_ifsflags &= ~flag; | req.ifbr_ifsflags &= ~flag; | ||||
if (do_cmd(sock, BRDGSIFFLGS, &req, sizeof(req), 1) < 0) | if (do_cmd(sock, BRDGSIFFLGS, &req, sizeof(req), 1) < 0) | ||||
err(1, "unable to set bridge flags"); | err(1, "unable to set bridge flags"); | ||||
} | } | ||||
static void | static void | ||||
bridge_interfaces(int s, const char *prefix) | |||||
{ | |||||
struct ifbifconf bifc; | |||||
struct ifbreq *req; | |||||
char *inbuf = NULL, *ninbuf; | |||||
char *p, *pad; | |||||
int i, len = 8192; | |||||
pad = strdup(prefix); | |||||
if (pad == NULL) | |||||
err(1, "strdup"); | |||||
/* replace the prefix with whitespace */ | |||||
for (p = pad; *p != '\0'; p++) { | |||||
if(isprint(*p)) | |||||
*p = ' '; | |||||
} | |||||
for (;;) { | |||||
ninbuf = realloc(inbuf, len); | |||||
if (ninbuf == NULL) | |||||
err(1, "unable to allocate interface buffer"); | |||||
bifc.ifbic_len = len; | |||||
bifc.ifbic_buf = inbuf = ninbuf; | |||||
if (do_cmd(s, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0) | |||||
err(1, "unable to get interface list"); | |||||
if ((bifc.ifbic_len + sizeof(*req)) < len) | |||||
break; | |||||
len *= 2; | |||||
} | |||||
for (i = 0; i < bifc.ifbic_len / sizeof(*req); i++) { | |||||
req = bifc.ifbic_req + i; | |||||
printf("%s%s ", prefix, req->ifbr_ifsname); | |||||
printb("flags", req->ifbr_ifsflags, IFBIFBITS); | |||||
printf("\n"); | |||||
printf("%s", pad); | |||||
printf("ifmaxaddr %u", req->ifbr_addrmax); | |||||
printf(" port %u priority %u", req->ifbr_portno, | |||||
req->ifbr_priority); | |||||
printf(" path cost %u", req->ifbr_path_cost); | |||||
if (req->ifbr_ifsflags & IFBIF_STP) { | |||||
if (req->ifbr_proto < nitems(stpproto)) | |||||
printf(" proto %s", stpproto[req->ifbr_proto]); | |||||
else | |||||
printf(" <unknown proto %d>", | |||||
req->ifbr_proto); | |||||
printf("\n%s", pad); | |||||
if (req->ifbr_role < nitems(stproles)) | |||||
printf("role %s", stproles[req->ifbr_role]); | |||||
else | |||||
printf("<unknown role %d>", | |||||
req->ifbr_role); | |||||
if (req->ifbr_state < nitems(stpstates)) | |||||
printf(" state %s", stpstates[req->ifbr_state]); | |||||
else | |||||
printf(" <unknown state %d>", | |||||
req->ifbr_state); | |||||
} | |||||
printf("\n"); | |||||
} | |||||
free(pad); | |||||
free(inbuf); | |||||
} | |||||
static void | |||||
bridge_addresses(int s, const char *prefix) | bridge_addresses(int s, const char *prefix) | ||||
{ | { | ||||
struct ifbaconf ifbac; | struct ifbaconf ifbac; | ||||
struct ifbareq *ifba; | struct ifbareq *ifba; | ||||
char *inbuf = NULL, *ninbuf; | char *inbuf = NULL, *ninbuf; | ||||
int i, len = 8192; | int i, len = 8192; | ||||
struct ether_addr ea; | struct ether_addr ea; | ||||
Show All 21 Lines | bridge_addresses(int s, const char *prefix) | ||||
} | } | ||||
free(inbuf); | free(inbuf); | ||||
} | } | ||||
static void | static void | ||||
bridge_status(int s) | bridge_status(int s) | ||||
{ | { | ||||
struct ifbropreq ifbp; | ifconfig_handle_t *lifh; | ||||
struct ifbrparam param; | struct ifconfig_bridge_status *bridge; | ||||
u_int16_t pri; | struct ifbropreq *params; | ||||
u_int8_t ht, fd, ma, hc, pro; | const char *pad, *prefix; | ||||
u_int8_t lladdr[ETHER_ADDR_LEN]; | uint8_t lladdr[ETHER_ADDR_LEN]; | ||||
u_int16_t bprio; | uint16_t bprio; | ||||
u_int32_t csize, ctime; | |||||
if (do_cmd(s, BRDGGCACHE, ¶m, sizeof(param), 0) < 0) | lifh = ifconfig_open(); | ||||
if (lifh == NULL) | |||||
kp: At what point to we switch to a single global lifh variable throughout ifconfig? | |||||
Not Done Inline ActionsMy thinking is that eventually it will be possible to replace the socket parameter s with a lifh parameter for the handle for all these command handlers. A global handle could work in the meantime. freqlabs: My thinking is that eventually it will be possible to replace the socket parameter `s` with a… | |||||
Not Done Inline ActionsYeah, that works too. ifconfig is mostly old, and in desperate need of some more cleanup. Hopefully moving things in libifconfig will make that easier. kp: Yeah, that works too.
ifconfig is mostly old, and in desperate need of some more cleanup. | |||||
return; | return; | ||||
csize = param.ifbrp_csize; | |||||
if (do_cmd(s, BRDGGTO, ¶m, sizeof(param), 0) < 0) | |||||
return; | |||||
ctime = param.ifbrp_ctime; | |||||
if (do_cmd(s, BRDGPARAM, &ifbp, sizeof(ifbp), 0) < 0) | |||||
return; | |||||
pri = ifbp.ifbop_priority; | |||||
pro = ifbp.ifbop_protocol; | |||||
ht = ifbp.ifbop_hellotime; | |||||
fd = ifbp.ifbop_fwddelay; | |||||
hc = ifbp.ifbop_holdcount; | |||||
ma = ifbp.ifbop_maxage; | |||||
PV2ID(ifbp.ifbop_bridgeid, bprio, lladdr); | if (ifconfig_bridge_get_bridge_status(lifh, name, &bridge) == -1) | ||||
goto close; | |||||
params = bridge->params; | |||||
PV2ID(params->ifbop_bridgeid, bprio, lladdr); | |||||
printf("\tid %s priority %u hellotime %u fwddelay %u\n", | printf("\tid %s priority %u hellotime %u fwddelay %u\n", | ||||
ether_ntoa((struct ether_addr *)lladdr), pri, ht, fd); | ether_ntoa((struct ether_addr *)lladdr), | ||||
params->ifbop_priority, | |||||
params->ifbop_hellotime, | |||||
params->ifbop_fwddelay); | |||||
printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n", | printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n", | ||||
ma, hc, stpproto[pro], csize, ctime); | params->ifbop_maxage, | ||||
params->ifbop_holdcount, | |||||
PV2ID(ifbp.ifbop_designated_root, bprio, lladdr); | stpproto[params->ifbop_protocol], | ||||
bridge->cache_size, | |||||
bridge->cache_lifetime); | |||||
PV2ID(params->ifbop_designated_root, bprio, lladdr); | |||||
printf("\troot id %s priority %d ifcost %u port %u\n", | printf("\troot id %s priority %d ifcost %u port %u\n", | ||||
ether_ntoa((struct ether_addr *)lladdr), bprio, | ether_ntoa((struct ether_addr *)lladdr), | ||||
ifbp.ifbop_root_path_cost, ifbp.ifbop_root_port & 0xfff); | bprio, | ||||
params->ifbop_root_path_cost, | |||||
params->ifbop_root_port & 0xfff); | |||||
bridge_interfaces(s, "\tmember: "); | prefix = "\tmember: "; | ||||
pad = "\t "; | |||||
for (size_t i = 0; i < bridge->members_count; ++i) { | |||||
struct ifbreq *member = &bridge->members[i]; | |||||
return; | printf("%s%s ", prefix, member->ifbr_ifsname); | ||||
printb("flags", member->ifbr_ifsflags, IFBIFBITS); | |||||
printf("\n%s", pad); | |||||
printf("ifmaxaddr %u port %u priority %u path cost %u", | |||||
Done Inline Actionsbridge->members[i]? kp: bridge->members[i]? | |||||
member->ifbr_addrmax, | |||||
member->ifbr_portno, | |||||
member->ifbr_priority, | |||||
member->ifbr_path_cost); | |||||
if (member->ifbr_ifsflags & IFBIF_STP) { | |||||
uint8_t proto = member->ifbr_proto; | |||||
uint8_t role = member->ifbr_role; | |||||
uint8_t state = member->ifbr_state; | |||||
if (proto < nitems(stpproto)) | |||||
printf(" proto %s", stpproto[proto]); | |||||
else | |||||
printf(" <unknown proto %d>", proto); | |||||
printf("\n%s", pad); | |||||
if (role < nitems(stproles)) | |||||
printf("role %s", stproles[role]); | |||||
else | |||||
printf("<unknown role %d>", role); | |||||
if (state < nitems(stpstates)) | |||||
printf(" state %s", stpstates[state]); | |||||
else | |||||
printf(" <unknown state %d>", state); | |||||
} | |||||
printf("\n"); | |||||
} | |||||
Done Inline ActionsI think style(9) still wants us to put those at the top of the block. kp: I think style(9) still wants us to put those at the top of the block. | |||||
ifconfig_bridge_free_bridge_status(bridge); | |||||
close: | |||||
ifconfig_close(lifh); | |||||
} | } | ||||
static void | static void | ||||
setbridge_add(const char *val, int d, int s, const struct afswtch *afp) | setbridge_add(const char *val, int d, int s, const struct afswtch *afp) | ||||
{ | { | ||||
struct ifbreq req; | struct ifbreq req; | ||||
memset(&req, 0, sizeof(req)); | memset(&req, 0, sizeof(req)); | ||||
▲ Show 20 Lines • Show All 459 Lines • Show Last 20 Lines |
At what point to we switch to a single global lifh variable throughout ifconfig?