From 84e4ad616c22364f46b75be134ecf250656073aa Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 8 Apr 2022 12:41:56 +0200 Subject: [PATCH] more debug logs / address printing --- tr-bridge.c | 29 +++++++++++++++++++++++------ utils.c | 8 ++++++++ utils.h | 3 +++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tr-bridge.c b/tr-bridge.c index 68afe8e..912a17d 100644 --- a/tr-bridge.c +++ b/tr-bridge.c @@ -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) { + 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]; const struct ethhdr *ethh = (struct ethhdr *) buf; struct tr_hdr trh; @@ -189,8 +190,12 @@ static int eth2tr(struct bridge_state *bst) 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)) { - 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; } @@ -201,9 +206,13 @@ static int eth2tr(struct bridge_state *bst) memcpy(&trh.saddr, ethh->h_source, sizeof(trh.saddr)); 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)); - else { + } else { printf("TR<-ETH: Ignoring frame to unknown MAC %s\n", mac2str(trh.daddr)); 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) { + 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]; const struct tr_hdr *trh = (const struct tr_hdr *) buf; struct ethhdr ethh; @@ -243,9 +253,12 @@ static int tr2eth(struct bridge_state *bst) fprintf(stderr, "short frame from TR\n"); return 0; } + mac2str_buf(tr_src, trh->saddr); + mac2str_buf(tr_dst, trh->daddr); 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; } @@ -255,9 +268,13 @@ static int tr2eth(struct bridge_state *bst) osmo_revbytebits_buf(ethh.h_source, TR_ALEN); 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, ðh, buf + sizeof(*trh), trlen - sizeof(*trh)); - else { + } else { printf("TR->ETH: Ignoring frame to unknown MAC %s\n", mac2str(ethh.h_dest)); return 0; } diff --git a/utils.c b/utils.c index 4c68845..0874a14 100644 --- a/utils.c +++ b/utils.c @@ -42,6 +42,14 @@ void osmo_revbytebits_buf(uint8_t *buf, int len) 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) { static char buf[32]; diff --git a/utils.h b/utils.h index d5171e4..5ce28e4 100644 --- a/utils.h +++ b/utils.h @@ -3,3 +3,6 @@ void osmo_revbytebits_buf(uint8_t *buf, int len); const char *mac2str(const uint8_t *addr); +const char *mac2str_buf(char *buf, const uint8_t *addr); + +#define MAC_STR_SIZE (6*3)