added packet forwarding and replaceable routing modules.

This commit is contained in:
nvt-se 2009-04-06 13:18:50 +00:00
parent 461ba4082c
commit 3b2ad9cfc4
2 changed files with 63 additions and 6 deletions

View file

@ -47,7 +47,7 @@
* *
* This file is part of the uIP TCP/IP stack. * This file is part of the uIP TCP/IP stack.
* *
* $Id: uip.h,v 1.23 2009/03/15 20:21:16 nvt-se Exp $ * $Id: uip.h,v 1.24 2009/04/06 13:18:50 nvt-se Exp $
* *
*/ */
@ -1355,6 +1355,21 @@ struct uip_udp_conn {
extern struct uip_udp_conn *uip_udp_conn; extern struct uip_udp_conn *uip_udp_conn;
extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
struct uip_router {
int (*activate)(void);
int (*deactivate)(void);
uip_ipaddr_t *(*lookup)(uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop);
};
#if UIP_CONF_ROUTER
extern const struct uip_router *uip_router;
/**
* uIP routing driver registration function.
*/
void uip_router_register(const struct uip_router *router);
#endif /*UIP_CONF_ROUTER*/
#if UIP_CONF_ICMP6 #if UIP_CONF_ICMP6
struct uip_icmp6_conn { struct uip_icmp6_conn {
uip_icmp6_appstate_t appstate; uip_icmp6_appstate_t appstate;
@ -1385,6 +1400,8 @@ struct uip_stats {
layer. */ layer. */
uip_stats_t sent; /**< Number of sent packets at the IP uip_stats_t sent; /**< Number of sent packets at the IP
layer. */ layer. */
uip_stats_t forwarded;/**< Number of forwarded packets at the IP
layer. */
uip_stats_t drop; /**< Number of dropped packets at the IP uip_stats_t drop; /**< Number of dropped packets at the IP
layer. */ layer. */
uip_stats_t vhlerr; /**< Number of packets dropped due to wrong uip_stats_t vhlerr; /**< Number of packets dropped due to wrong

View file

@ -41,7 +41,7 @@
* *
* This file is part of the uIP TCP/IP stack. * This file is part of the uIP TCP/IP stack.
* *
* $Id: uip6.c,v 1.4 2009/03/10 08:00:59 julienabeille Exp $ * $Id: uip6.c,v 1.5 2009/04/06 13:18:51 nvt-se Exp $
* *
*/ */
@ -256,6 +256,13 @@ struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
#endif /* UIP_UDP */ #endif /* UIP_UDP */
/** @} */ /** @} */
/*---------------------------------------------------------------------------*/
/** @{ \name Routing module */
/*---------------------------------------------------------------------------*/
#if UIP_CONF_ROUTER
const struct uip_router *uip_router;
#endif /* UIP_CONF_ROUTER */
/** @} */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @{ \name ICMPv6 variables */ /** @{ \name ICMPv6 variables */
@ -421,7 +428,19 @@ uip_init(void)
#endif /* UIP_UDP */ #endif /* UIP_UDP */
} }
/*---------------------------------------------------------------------------*/
#if UIP_CONF_ROUTER
void
uip_router_register(const struct uip_router *router) {
if(uip_router != NULL) {
uip_router->deactivate();
}
uip_router = router;
if(uip_router != NULL) {
router->activate();
}
}
#endif /*UIP_CONF_ROUTER*/
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if UIP_TCP && UIP_ACTIVE_OPEN #if UIP_TCP && UIP_ACTIVE_OPEN
struct uip_conn * struct uip_conn *
@ -1065,6 +1084,23 @@ uip_process(u8_t flag)
goto drop; goto drop;
} }
#if UIP_CONF_ROUTER
if(!uip_netif_is_addr_my_unicast(&UIP_IP_BUF->destipaddr) &&
!uip_netif_is_addr_my_solicited(&UIP_IP_BUF->destipaddr)) {
if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr) &&
!uip_is_addr_link_local(&UIP_IP_BUF->destipaddr)) {
PRINTF("Forwarding packet to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
UIP_STAT(++uip_stat.ip.forwarded);
goto send;
} else if(!uip_is_addr_linklocal_allnodes_mcast(&UIP_IP_BUF->destipaddr)) {
PRINTF("Dropping packet, not for me\n");
UIP_STAT(++uip_stat.ip.drop);
goto drop;
}
}
#else
if(!uip_netif_is_addr_my_unicast(&UIP_IP_BUF->destipaddr) && if(!uip_netif_is_addr_my_unicast(&UIP_IP_BUF->destipaddr) &&
!uip_netif_is_addr_my_solicited(&UIP_IP_BUF->destipaddr) && !uip_netif_is_addr_my_solicited(&UIP_IP_BUF->destipaddr) &&
!uip_is_addr_linklocal_allnodes_mcast(&UIP_IP_BUF->destipaddr)){ !uip_is_addr_linklocal_allnodes_mcast(&UIP_IP_BUF->destipaddr)){
@ -1072,7 +1108,7 @@ uip_process(u8_t flag)
UIP_STAT(++uip_stat.ip.drop); UIP_STAT(++uip_stat.ip.drop);
goto drop; goto drop;
} }
#endif /* UIP_CONF_ROUTER */
/* /*
* Next header field processing. In IPv6, we can have extension headers, * Next header field processing. In IPv6, we can have extension headers,
@ -1256,6 +1292,10 @@ uip_process(u8_t flag)
case ICMP6_NA: case ICMP6_NA:
uip_nd6_io_na_input(); uip_nd6_io_na_input();
break; break;
case ICMP6_RS:
UIP_STAT(++uip_stat.icmp.drop);
uip_len = 0;
break;
case ICMP6_RA: case ICMP6_RA:
uip_nd6_io_ra_input(); uip_nd6_io_ra_input();
break; break;