more debug logs / address printing

This commit is contained in:
Harald Welte 2022-04-08 12:41:56 +02:00
parent 995ac55d0e
commit 84e4ad616c
3 changed files with 34 additions and 6 deletions

View File

@ -172,6 +172,7 @@ static int write_tr(int socket, const struct tr_hdr *trh, const uint8_t *payload
static int eth2tr(struct bridge_state *bst) static int eth2tr(struct bridge_state *bst)
{ {
char tr_src[MAC_STR_SIZE], tr_dst[MAC_STR_SIZE], eth_src[MAC_STR_SIZE], eth_dst[MAC_STR_SIZE];
uint8_t buf[2000]; uint8_t buf[2000];
const struct ethhdr *ethh = (struct ethhdr *) buf; const struct ethhdr *ethh = (struct ethhdr *) buf;
struct tr_hdr trh; struct tr_hdr trh;
@ -189,8 +190,12 @@ static int eth2tr(struct bridge_state *bst)
return 0; return 0;
} }
mac2str_buf(eth_src, ethh->h_source);
mac2str_buf(eth_dst, ethh->h_dest);
if (ethh->h_proto != htons(ETH_P_802_2)) { if (ethh->h_proto != htons(ETH_P_802_2)) {
fprintf(stderr, "TR<-ETH: Not bridging unexpected frame for proto 0x%04x\n", ntohs(ethh->h_proto)); fprintf(stderr, "TR<-ETH: Not bridging unexpected frame for proto %s->%s 0x%04x\n",
eth_src, eth_dst, ntohs(ethh->h_proto));
return 0; return 0;
} }
@ -201,9 +206,13 @@ static int eth2tr(struct bridge_state *bst)
memcpy(&trh.saddr, ethh->h_source, sizeof(trh.saddr)); memcpy(&trh.saddr, ethh->h_source, sizeof(trh.saddr));
osmo_revbytebits_buf(trh.saddr, TR_ALEN); osmo_revbytebits_buf(trh.saddr, TR_ALEN);
if (mac_table_empty(&bst->tr.mac_tbl) || mac_table_contains(&bst->tr.mac_tbl, trh.daddr)) mac2str_buf(tr_src, trh.saddr);
mac2str_buf(tr_dst, trh.daddr);
if (mac_table_empty(&bst->tr.mac_tbl) || mac_table_contains(&bst->tr.mac_tbl, trh.daddr)) {
printf("TR<-ETH: %s/%s <- %s/%s\n", tr_src, eth_src, tr_dst, eth_dst);
return write_tr(bst->tr.socket, &trh, buf + sizeof(*ethh), ethlen - sizeof(*ethh)); return write_tr(bst->tr.socket, &trh, buf + sizeof(*ethh), ethlen - sizeof(*ethh));
else { } else {
printf("TR<-ETH: Ignoring frame to unknown MAC %s\n", mac2str(trh.daddr)); printf("TR<-ETH: Ignoring frame to unknown MAC %s\n", mac2str(trh.daddr));
return 0; return 0;
} }
@ -227,6 +236,7 @@ static int write_eth(int socket, const struct ethhdr *ethh, const uint8_t *paylo
static int tr2eth(struct bridge_state *bst) static int tr2eth(struct bridge_state *bst)
{ {
char tr_src[MAC_STR_SIZE], tr_dst[MAC_STR_SIZE], eth_src[MAC_STR_SIZE], eth_dst[MAC_STR_SIZE];
uint8_t buf[2000]; uint8_t buf[2000];
const struct tr_hdr *trh = (const struct tr_hdr *) buf; const struct tr_hdr *trh = (const struct tr_hdr *) buf;
struct ethhdr ethh; struct ethhdr ethh;
@ -243,9 +253,12 @@ static int tr2eth(struct bridge_state *bst)
fprintf(stderr, "short frame from TR\n"); fprintf(stderr, "short frame from TR\n");
return 0; return 0;
} }
mac2str_buf(tr_src, trh->saddr);
mac2str_buf(tr_dst, trh->daddr);
if (trh->fc != LLC_FRAME) { if (trh->fc != LLC_FRAME) {
fprintf(stderr, "TR->ETH: Not bridging unexpected non-LLC frame for FC 0x%02x\n", trh->fc); fprintf(stderr, "TR->ETH: Not bridging unexpected non-LLC frame %s->%s FC 0x%02x\n",
tr_src, tr_dst, trh->fc);
return 0; return 0;
} }
@ -255,9 +268,13 @@ static int tr2eth(struct bridge_state *bst)
osmo_revbytebits_buf(ethh.h_source, TR_ALEN); osmo_revbytebits_buf(ethh.h_source, TR_ALEN);
ethh.h_proto = htons(ETH_P_802_2); ethh.h_proto = htons(ETH_P_802_2);
if (mac_table_empty(&bst->eth.mac_tbl) || mac_table_contains(&bst->eth.mac_tbl, ethh.h_dest)) mac2str_buf(eth_src, ethh.h_source);
mac2str_buf(eth_dst, ethh.h_dest);
if (mac_table_empty(&bst->eth.mac_tbl) || mac_table_contains(&bst->eth.mac_tbl, ethh.h_dest)) {
printf("TR->ETH: %s/%s -> %s/%s\n", tr_src, eth_src, tr_dst, eth_dst);
return write_eth(bst->eth.socket, &ethh, buf + sizeof(*trh), trlen - sizeof(*trh)); return write_eth(bst->eth.socket, &ethh, buf + sizeof(*trh), trlen - sizeof(*trh));
else { } else {
printf("TR->ETH: Ignoring frame to unknown MAC %s\n", mac2str(ethh.h_dest)); printf("TR->ETH: Ignoring frame to unknown MAC %s\n", mac2str(ethh.h_dest));
return 0; return 0;
} }

View File

@ -42,6 +42,14 @@ void osmo_revbytebits_buf(uint8_t *buf, int len)
buf[i] = flip_table[buf[i]]; buf[i] = flip_table[buf[i]];
} }
const char *mac2str_buf(char *buf, const uint8_t *addr)
{
sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
return buf;
}
const char *mac2str(const uint8_t *addr) const char *mac2str(const uint8_t *addr)
{ {
static char buf[32]; static char buf[32];

View File

@ -3,3 +3,6 @@
void osmo_revbytebits_buf(uint8_t *buf, int len); void osmo_revbytebits_buf(uint8_t *buf, int len);
const char *mac2str(const uint8_t *addr); const char *mac2str(const uint8_t *addr);
const char *mac2str_buf(char *buf, const uint8_t *addr);
#define MAC_STR_SIZE (6*3)