diff --git a/src/sys/include/net/netif.h b/src/sys/include/net/netif.h index f4f233b..5aaba47 100644 --- a/src/sys/include/net/netif.h +++ b/src/sys/include/net/netif.h @@ -65,6 +65,11 @@ void route_cache_init(); +struct route_cache *route_cache_add(struct ip_addr *ipaddr, + struct ip_addr *netmask, + struct ip_addr *gw, + void (* init)(struct route_cache *route_cache)); + struct netif { struct netif *next; uInt8 num; diff --git a/src/sys/net/core/netif.c b/src/sys/net/core/netif.c index 7736bd4..4018430 100644 --- a/src/sys/net/core/netif.c +++ b/src/sys/net/core/netif.c @@ -145,9 +145,38 @@ netif_list = netif_default = NULL; } /*-----------------------------------------------------------------------------------*/ + +/* Add to the Route Cache */ +struct route_cache * +route_cache_add(struct ip_addr *ipaddr, struct ip_addr *netmask, + struct ip_addr *gw, + void (* init)(struct route_cache *route_cache)) +{ + struct route_cache *route_cache; + static int route_cache_num = 0; + + route_cache = mem_malloc(sizeof(struct route_cache)); + + if(route_cache == NULL) { + return NULL; + } + + route_cache->num = route_cache_num++; + ip_addr_set(&(route_cache->ip_addr), ipaddr); + ip_addr_set(&(route_cache->netmask), netmask); + ip_addr_set(&(route_cache->gw), gw); + + init(route_cache); + + route_cache->next = route_cache_list; + route_cache_list = route_cache; + return route_cache; +} + /* initialize the Route Cache */ void route_cache_init(void) { route_cache_list = NULL; } +