int microps_init (void) { if (ethernet_init() == -1) { goto ERROR; } if (slip_init() == -1) { goto ERROR; } if (arp_init() == -1) { goto ERROR; } if (ip_init() == -1) { goto ERROR; } if (icmp_init() == -1) { goto ERROR; } if (udp_init() == -1) { goto ERROR; } if (tcp_init() == -1) { goto ERROR; } return 0; ERROR: microps_cleanup(); return -1; }
int microps_init (const struct microps_param *param) { if (ethernet_init() == -1) { goto ERROR; } if (ethernet_device_open(param->ethernet_device, param->ethernet_addr) == -1) { goto ERROR; } if (arp_init() == -1) { goto ERROR; } if (ip_init(param->ip_addr, param->ip_netmask, param->ip_gateway) == -1) { goto ERROR; } if (icmp_init() == -1) { goto ERROR; } if (udp_init() == -1) { goto ERROR; } if (tcp_init() == -1) { goto ERROR; } if (ethernet_device_run() == -1) { goto ERROR; } return 0; ERROR: //microps_cleanup(); return -1; }
/* * IP initialization: fill in IP protocol switch table. * All protocols not implemented in kernel go to raw IP protocol handler. */ void ip_init(Slirp *slirp) { slirp->ipq.ip_link.next = slirp->ipq.ip_link.prev = &slirp->ipq.ip_link; udp_init(slirp); tcp_init(slirp); icmp_init(slirp); }
void net_init (void) { int32 nbufs; /* Total no of buffers */ /* Initialize the network data structure */ memset((char *)&NetData, NULLCH, sizeof(struct network)); /* Obtain the Ethernet MAC address */ control(ETHER0, ETH_CTRL_GET_MAC, (int32)NetData.ethucast, 0); memset((char *)NetData.ethbcast, 0xFF, ETH_ADDR_LEN); /* Initialize the random port seed */ netportseed = getticks(); /* Create the network buffer pool */ nbufs = UDP_SLOTS * UDP_QSIZ + ICMP_SLOTS * ICMP_QSIZ + 1; netbufpool = mkbufpool(PACKLEN, nbufs); /* Initialize the ARP cache */ arp_init(); /* Initialize UDP */ udp_init(); /* Initialize ICMP */ icmp_init(); /* Initialize the IP output queue */ ipoqueue.iqhead = 0; ipoqueue.iqtail = 0; ipoqueue.iqsem = semcreate(0); if((int32)ipoqueue.iqsem == SYSERR) { panic("Cannot create ip output queue semaphore"); return; } /* Create the IP output process */ resume(create(ipout, NETSTK, NETPRIO, "ipout", 0, NULL)); /* Create a network input process */ resume(create(netin, NETSTK, NETPRIO, "netin", 0, NULL)); }
extern void #MARK_init(void); void init_extensions(void) { ah_init(); addrtype_init(); comment_init(); 2connmark_init(); conntrack_init(); 2dscp_init(); 2ecn_init(); esp_init(); hashlimit_init(); helper_init(); icmp_init(); iprange_init(); length_init(); limit_init(); mac_init(); multiport_init(); #2mark_init(); owner_init(); physdev_init(); pkttype_init(); policy_init(); realm_init(); sctp_init(); standard_init(); state_init(); tcp_init(); 2tcpmss_init(); 2tos_init(); 2ttl_init(); udp_init(); unclean_init(); CLASSIFY_init(); CONNMARK_init(); DNAT_init(); LOG_init(); #DSCP_init(); ECN_init(); MASQUERADE_init(); MIRROR_init(); NETMAP_init(); NFQUEUE_init(); NOTRACK_init(); REDIRECT_init(); REJECT_init(); #MARK_init(); }
void net_init (void) { int32 iface; /* index into interface table */ char str[16]; /* string to hold process name */ /* Initialize interface data structures */ netiface_init(); /* Initialize ARP cache for each interface */ for (iface=0; iface<NIFACES; iface++) { arp_init(iface); } /* Initialize UDP */ udp_init(); /* Initialize ICMP */ icmp_init(); /* Create a network input process for each interface */ for (iface=0; iface<NIFACES; iface++) { sprintf(str, "net%d_input", iface); resume(create(netin, 4196, 5000, str, 1, iface)); } /* Initialize the IP output queue */ ipoqueue.iqtail = ipoqueue.iqhead = 0; ipoqueue.iqsem = semcreate(0); /* Create an IP output process */ resume(create(ipout, 2048, 6000, "ip_output", 0)); /* Create a low-level input process that reads raw frames and */ /* demultiplexes them to the correct interface */ resume(create(rawin, 2048, 8000, "raw_input", 0)); }
int main(int argc,char **argv) { if (argc < 3) { printf("Syntax :\n %s local_ip slip_tty\n",argv[0]); exit(3); } debug("KTCP: Mark 1.\n"); local_ip = in_aton(argv[1]); debug("KTCP: Mark 2.\n"); if((tcpdevfd = tcpdev_init("/dev/tcpdev")) < 0) exit(1); debug("KTCP: Mark 3.\n"); if ((sfd = slip_init(argv[2])) < 0) exit(2); debug("KTCP: Mark 4.\n"); ip_init(); debug("KTCP: Mark 5.\n"); icmp_init(); debug("KTCP: Mark 6.\n"); tcp_init(); debug("KTCP: Mark 7.\n"); netconf_init(); debug("KTCP: Mark 8.\n"); ktcp_run(); debug("KTCP: Mark 9.\n"); exit(0); }
PUBLIC void ip_init() { int i, j, result; ip_ass_t *ip_ass; ip_fd_t *ip_fd; ip_port_t *ip_port; struct ip_conf *icp; assert (BUF_S >= sizeof(struct nwio_ethopt)); assert (BUF_S >= IP_MAX_HDR_SIZE + ETH_HDR_SIZE); assert (BUF_S >= sizeof(nwio_ipopt_t)); assert (BUF_S >= sizeof(nwio_route_t)); for (i=0, ip_ass= ip_ass_table; i<IP_ASS_NR; i++, ip_ass++) { ip_ass->ia_frags= 0; ip_ass->ia_first_time= 0; ip_ass->ia_port= 0; } for (i=0, ip_fd= ip_fd_table; i<IP_FD_NR; i++, ip_fd++) { ip_fd->if_flags= IFF_EMPTY; ip_fd->if_rdbuf_head= 0; } for (i=0, ip_port= ip_port_table, icp= ip_conf; i<ip_conf_nr; i++, ip_port++, icp++) { ip_port->ip_port= i; ip_port->ip_flags= IPF_EMPTY; ip_port->ip_dev_main= (ip_dev_t)ip_bad_callback; ip_port->ip_dev_set_ipaddr= (ip_dev_t)ip_bad_callback; ip_port->ip_dev_send= (ip_dev_send_t)ip_bad_callback; ip_port->ip_dl_type= icp->ic_devtype; ip_port->ip_mtu= IP_DEF_MTU; ip_port->ip_mtu_max= IP_MAX_PACKSIZE; switch(ip_port->ip_dl_type) { case IPDL_ETH: ip_port->ip_dl.dl_eth.de_port= icp->ic_port; result= ipeth_init(ip_port); if (result == -1) continue; assert(result == NW_OK); break; case IPDL_PSIP: ip_port->ip_dl.dl_ps.ps_port= icp->ic_port; result= ipps_init(ip_port); if (result == -1) continue; assert(result == NW_OK); break; default: ip_panic(( "unknown ip_dl_type %d", ip_port->ip_dl_type )); break; } ip_port->ip_loopb_head= NULL; ip_port->ip_loopb_tail= NULL; ev_init(&ip_port->ip_loopb_event); ip_port->ip_routeq_head= NULL; ip_port->ip_routeq_tail= NULL; ev_init(&ip_port->ip_routeq_event); ip_port->ip_flags |= IPF_CONFIGURED; ip_port->ip_proto_any= NULL; for (j= 0; j<IP_PROTO_HASH_NR; j++) ip_port->ip_proto[j]= NULL; } #ifndef BUF_CONSISTENCY_CHECK bf_logon(ip_buffree); #else bf_logon(ip_buffree, ip_bufcheck); #endif icmp_init(); ipr_init(); for (i=0, ip_port= ip_port_table; i<ip_conf_nr; i++, ip_port++) { if (!(ip_port->ip_flags & IPF_CONFIGURED)) continue; ip_port->ip_frame_id= (u16_t)get_time(); sr_add_minor(if2minor(ip_conf[i].ic_ifno, IP_DEV_OFF), i, ip_open, ip_close, ip_read, ip_write, ip_ioctl, ip_cancel, ip_select); (*ip_port->ip_dev_main)(ip_port); } }
int main() { //###################################################################### //TODO get this from config file eventually //host interface my_host_mac_addr = 0x080027445566ull; my_host_ip_addr = IP4_ADR_P2H(192,168,1,20); my_host_mask = IP4_ADR_P2H(255,255,255,0); //loopback interface loopback_ip_addr = IP4_ADR_P2H(127,0,0,1); loopback_mask = IP4_ADR_P2H(255,0,0,0); //any any_ip_addr = IP4_ADR_P2H(0,0,0,0); //###################################################################### sem_init(&control_serial_sem, 0, 1); //TODO remove after gen_control_serial_num() converted to RNG signal(SIGINT, termination_handler); //register termination handler // Start the driving thread of each module PRINT_DEBUG("Initialize Modules"); switch_init(); //should always be first daemon_init(); //TODO improve how sets mac/ip interface_init(); arp_init(); arp_register_interface(my_host_mac_addr, my_host_ip_addr); ipv4_init(); set_interface(my_host_ip_addr, my_host_mask); set_loopback(loopback_ip_addr, loopback_mask); icmp_init(); tcp_init(); udp_init(); //rtm_init(); //TODO when updated/fully implemented pthread_attr_t fins_pthread_attr; pthread_attr_init(&fins_pthread_attr); PRINT_DEBUG("Run/start Modules"); switch_run(&fins_pthread_attr); daemon_run(&fins_pthread_attr); interface_run(&fins_pthread_attr); arp_run(&fins_pthread_attr); ipv4_run(&fins_pthread_attr); icmp_run(&fins_pthread_attr); tcp_run(&fins_pthread_attr); udp_run(&fins_pthread_attr); //rtm_run(&fins_pthread_attr); //############################# //TODO custom test, remove later /* if (0) { char recv_data[4000]; while (1) { gets(recv_data); PRINT_DEBUG("Sending ARP req"); metadata *params_req = (metadata *) malloc(sizeof(metadata)); if (params_req == NULL) { PRINT_ERROR("metadata alloc fail"); exit(-1); } metadata_create(params_req); uint32_t dst_ip = IP4_ADR_P2H(192, 168, 1, 11); //uint32_t dst_ip = IP4_ADR_P2H(172, 31, 50, 152); uint32_t src_ip = IP4_ADR_P2H(192, 168, 1, 20); //uint32_t src_ip = IP4_ADR_P2H(172, 31, 50, 160); metadata_writeToElement(params_req, "dst_ip", &dst_ip, META_TYPE_INT32); metadata_writeToElement(params_req, "src_ip", &src_ip, META_TYPE_INT32); struct finsFrame *ff_req = (struct finsFrame*) malloc(sizeof(struct finsFrame)); if (ff_req == NULL) { PRINT_ERROR("todo error"); //metadata_destroy(params_req); exit(-1); } ff_req->dataOrCtrl = CONTROL; ff_req->destinationID.id = ARP_ID; ff_req->destinationID.next = NULL; ff_req->metaData = params_req; ff_req->ctrlFrame.senderID = IP_ID; ff_req->ctrlFrame.serial_num = gen_control_serial_num(); ff_req->ctrlFrame.opcode = CTRL_EXEC; ff_req->ctrlFrame.param_id = EXEC_ARP_GET_ADDR; ff_req->ctrlFrame.data_len = 0; ff_req->ctrlFrame.data = NULL; arp_to_switch(ff_req); //doesn't matter which queue } } //############################# */ while (1) ; return (1); }