struct sr_instance* get_sr() { struct sr_instance* sr; sr = sr_get_global_instance( NULL ); assert( sr ); return sr; }
/* Given a destination ip address: * - find interface the packet would be shipped through * - return this interface's ip address as the src ip address */ uint32_t find_srcip(uint32_t dest) { struct sr_instance* sr = sr_get_global_instance(0); router_state* rs = (router_state*)sr->interface_subsystem; iface_entry* iface_struct; char *iface = 0; struct in_addr dst; struct in_addr src; uint32_t srcip; iface = calloc(32, sizeof(char)); dst.s_addr = dest; src.s_addr = 0; lock_if_list_rd(rs); lock_rtable_rd(rs); if(get_next_hop(&src, iface, 32, rs, &dst)) { srcip = 0; } else { iface_struct = get_iface(rs, iface); assert(iface_struct); srcip = iface_struct->ip; } unlock_rtable(rs); unlock_if_list(rs); return srcip; }
uint32_t integ_ip_output(uint8_t *payload, uint8_t proto, uint32_t src, uint32_t dest, int len) { assert(payload); struct sr_instance* sr = sr_get_global_instance(0); int retval = send_ip_packet(sr, proto, src, dest, payload, len); free(payload); return retval; }
static void sr_low_level_network_subsystem(void *arg) { struct sr_instance* sr = (struct sr_instance*)arg; /* -- set argument as global singleton -- */ sr_get_global_instance(sr); #ifdef _CPUMODE_ /* -- whizbang main loop ;-) */ while( sr_cpu_input(sr) == 1); #else /* -- whizbang main loop ;-) */ while( sr_vns_read_from_server(sr) == 1); #endif /* -- this is the end ... my only friend .. the end -- */ sr_destroy_instance(sr); } /* -- sr_low_level_network_subsystem -- */