From 69d99cae896d4fde2f42e2242fc86f36dd6c910a Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 4 Nov 2017 11:44:06 +0000 Subject: [PATCH] netd: first attempt at decoding loopback correctly for non ARP protocols --- Applications/netd/netd.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Applications/netd/netd.c b/Applications/netd/netd.c index 3129b7cf..6256948d 100644 --- a/Applications/netd/netd.c +++ b/Applications/netd/netd.c @@ -597,7 +597,6 @@ int dokernel( void ) m->tsize[last] = sm.sd.tlen[last]; } if ( sm.sd.event & NEV_READ ){ - int last; m->rstart = sm.sd.rbuf; m->rend = sm.sd.rnext; } @@ -619,19 +618,33 @@ void send_or_loop( void ) we'll have to filter for IP address, rather */ static uint8_t broad[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - /* on broadcast send to self and peers */ - if (!memcmp(uip_buf, &broad[0], 6 )){ - looplen = uip_len; + + if (has_arp) { + + /* on broadcast send to self and peers */ + if (!memcmp(uip_buf, &broad[0], 6 )){ + looplen = uip_len; + device_send(uip_buf, uip_len); + return; + } + /* if dest is our mac then just send to self, no peers */ + if (!memcmp(uip_buf, &uip_lladdr.addr[0], 6)){ + looplen = uip_len; + return; + } + /* if else then just send to peers */ device_send(uip_buf, uip_len); - return; - } - /* if dest is our mac then just send to self, no peers */ - if (!memcmp(uip_buf, &uip_lladdr.addr[0], 6)){ - looplen = uip_len; - return; + } else { + uint8_t *bp = uip_buf + 14; /* TODO don't hard code */ + if ((bp[0] & 0xF0) == 0x40) { /* IP v4 */ + /* 127.* or our address. We don't implement bcast + or mcast p2p */ + if (bp[16] == 127 || memcmp(bp + 16, &uip_hostaddr, 4) == 0) + looplen = uip_len; + else + device_send(uip_buf, uip_len); + } } - /* if else then just send to peers */ - device_send(uip_buf, uip_len); } int loop_or_read( void ) -- 2.34.1