From 844acb30b97092342c2a580dd8e3124e271ad400 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 20 Oct 2011 04:51:34 -0700 Subject: [PATCH] fix bug in get_destination --- drivers/net/mmnif.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/net/mmnif.c b/drivers/net/mmnif.c index 6ca4a96b..33fef2d8 100644 --- a/drivers/net/mmnif.c +++ b/drivers/net/mmnif.c @@ -417,7 +417,6 @@ static uint8_t mmnif_get_destination(struct netif *netif, struct pbuf *p) { struct ip_hdr *iphdr; ip_addr_p_t ip; - uint8_t core; /* grab the destination ip address out of the ip header * for internal routing the last ocet is interpreted as core ID. @@ -425,19 +424,7 @@ static uint8_t mmnif_get_destination(struct netif *netif, struct pbuf *p) iphdr = (struct ip_hdr *)(p->payload); ip = iphdr->dest; - /* check if the ip address is in the Local Area Network of the 48 cores */ - - /* if it's not the same network the router core is addressed - * Note: the router core is core 1 - */ - if (ip_addr_netcmp(&ip, &netif->ip_addr, &netif->netmask)) - return 1; - core = ip4_addr4(&ip); - - /* check if the address is legitimata else return router core again */ - if ((core) < 1 || (core > MMNIF_CORES)) - core = 1; - return core; + return ip4_addr4(&ip); } /* mmnif_rxbuff_alloc(): @@ -622,6 +609,12 @@ static err_t mmnif_tx(struct netif *netif, struct pbuf *p) goto drop_packet; } + /* check destination ip */ + if (BUILTIN_EXPECT((dest_ip < 1) || (dest_ip > MMNIF_CORES), 0)) { + DEBUGPRINTF("mmnif_tx: invalid destination IP %d => drop\n", dest_ip); + goto drop_packet; + } + /* allocate memory for the packet in the remote buffer */ realloc: write_address = mmnif_rxbuff_alloc(dest_ip, p->tot_len);