void btree_routes(struct avl_node * node, void *param, int depth) { struct RtMib *rtp = (struct RtMib *)node; GIO *gio = (GIO *)param; if (!rtp->ipRouteNextHop) /* empty slot */ return; brtcount++; /* if this is first entry, then display heading */ if(brtcount == 1) gio_printf(gio,"..IPaddr.......mask.........nexthop...iface..type\n"); while(depth--) gio_printf(gio, " "); gio_printf(gio, "%u.%u.%u.%u %u.%u.%u.%u %u.%u.%u.%u %d %s\n", PUSH_IPADDR(rtp->ipRouteDest), PUSH_IPADDR(rtp->ipRouteMask), PUSH_IPADDR(rtp->ipRouteNextHop), (int)rtp->ipRouteIfIndex, route_prots[(int)rtp->ipRouteProto]); }
/* FUNCTION: netmain_setip() * * Set an interface's IP address, subnet mask, and gateway * * PARAM1: CLI_CTX CLI context * * RETURNS: int 0 if successful, otherwise error code * * setip -i <iface> -a <IPaddr> -s <subnet> -g <gateway> */ STATIC int netmain_setip(CLI_CTX ctx) { GIO *gio = ctx->gio; struct cli_addr *ipaddr; unsigned int iface; NET ifp; if (!CLI_HELP(ctx)) { if (CLI_DEFINED(ctx, 'i')) { iface = (int)(CLI_VALUE(ctx, 'i')); if (((1 <= iface) && (iface <= ifNumber)) && ((ifp = nets[iface-1]) != (NET)NULL)) { if (CLI_DEFINED(ctx, 'a')) { ipaddr = (struct cli_addr *)CLI_VALUE(ctx, 'a'); ifp->n_ipaddr = *((ip_addr *)&ipaddr->addr[0]); } if (CLI_DEFINED(ctx, 's')) { ipaddr = (struct cli_addr *)CLI_VALUE(ctx, 's'); ifp->snmask = *((ip_addr *)&ipaddr->addr[0]); } if (CLI_DEFINED(ctx, 'g')) { ipaddr = (struct cli_addr *)CLI_VALUE(ctx, 'g'); ifp->n_defgw = *((ip_addr *)&ipaddr->addr[0]); } /* recompute the subnet broadcast addresses */ ifp->n_netbr = ifp->n_ipaddr | ~(ifp->snmask); ifp->n_netbr42 = ifp->n_ipaddr & ifp->snmask; ifp->n_subnetbr = ifp->n_ipaddr | ~(ifp->snmask); } else return (CLI_ERR_PARAM); } /* dump nets[] array */ for (iface = 0; iface < ifNumber; iface++) { if ((ifp = nets[iface]) != (NET)NULL) { gio_printf(gio, "%2d: %s - IPaddr = %u.%u.%u.%u, submask = %u.%u.%u.%u, gateway = %u.%u.%u.%u\n", iface+1, ifp->name, PUSH_IPADDR(ifp->n_ipaddr), PUSH_IPADDR(ifp->snmask), PUSH_IPADDR(ifp->n_defgw)); } } } return (0); }
/* FUNCTION: netmain_route_print() * * Print IP route table * * PARAM1: CLI_CTX CLI context * * RETURN: int 0 or error code */ STATIC int netmain_route_print(CLI_CTX ctx) { GIO *gio = ctx->gio; int rtcount = 0; uint32_t version; /* extract the IP protocol version */ version = (uint32_t)CLI_VALUE(ctx, 'v'); /* IPv4 */ if (version == 4) { #ifdef BTREE_ROUTES brtcount = 0; avldepthfirst((struct avl_node *)btreeRoot, btree_routes, gio, 0); rtcount = brtcount; #else /* not BTREE_ROUTES */ RTMIB rtp; if (!rt_mib) /* system not fully up yet */ return (-1); for (rtp = rt_mib; rtp < rt_mib + ipRoutes; rtp++) { if (!rtp->ipRouteNextHop) /* empty slot */ { continue; } rtcount++; if (rtcount == 1) { gio_printf(gio, "..IPaddr.......mask.........nexthop...iface..type\n"); } gio_printf(gio,"%u.%u.%u.%u %u.%u.%u.%u %u.%u.%u.%u %d %s\n", PUSH_IPADDR(rtp->ipRouteDest), PUSH_IPADDR(rtp->ipRouteMask), PUSH_IPADDR(rtp->ipRouteNextHop), (int)rtp->ipRouteIfIndex, route_prots[(int)rtp->ipRouteProto]); } #endif /* BTREE_ROUTES */ } else { /* unsupported version number */ return (CLI_ERR_PARAM); } if (rtcount == 0) { gio_printf(gio,"no IP routes set\n"); } return (0); }
int upnp_base(void * pio) { char * cp; u_long newbase; u_long oldrange; unsigned mask; cp = nextarg( ((GEN_IO)pio)->inbuf ); if(!*cp) { ns_printf(pio, "please enter IP address for new base\n"); return -1; } cp = parse_ipad(&newbase, &mask, cp); if(cp) { ns_printf(pio, "Bad IP address: %s\n", cp); return -1; } oldrange = dAUTO_IP_RANGE; dBASE_AUTO_IP_ADDRESS = htonl(newbase); /* store in local endian */ dMAX_AUTO_IP_ADDRESS = htonl(newbase + oldrange); ns_printf(pio, "Changed base of Auto-IP address pool to %u.%u.%u.%u\n", PUSH_IPADDR(newbase) ); return 0; }
int udp_flood(void * pio) { int i; /* index */ int e; /* tmp error holder */ int send_err; /* total send error count */ int no_pkt; /* times packet get failed */ u_short lport; /* local port for send (random) */ PACKET p; int addr_index; /* index into floodtargs[] */ ns_printf(pio, "sending UDP flood of %ld pkts to %u.%u.%u.%u\n", pktcount, PUSH_IPADDR(activehost) ); lport = udp_socket(); e = send_err = no_pkt = 0; addr_index = 0; for (i = 0; i < pktcount; i++) { p = udp_alloc((unsigned)deflength, 0); /* get packet for sending */ if(!p) { /* ns_printf(pio, "pkt alloc failed on send #%d\n", i); */ no_pkt++; continue; } p->nb_plen = deflength; /* if floodtargs array has any entries rotate through them, else send all * of the packets to activehost */ if(floodtargs[0] == 0) p->fhost = activehost; else { p->fhost = floodtargs[addr_index++]; /* get next host */ if(floodtargs[addr_index++] == 0) /* wrap if at end of list */ addr_index = 0; } e = udp_send(lport, fport, p); if(e) { send_err++; /* ns_printf(pio, "UDP send error %d on %d\n", e, i); */ continue; } } ns_printf(pio, "sent %d pkts, %d errors, %d no-pkt, last return code: %d\n", i - no_pkt, send_err, no_pkt, e); return e; }
int sock_list(void * pio) { struct inpcb * inp; struct socket * so; struct tcpcb * tp; if (tcb.inp_next == NULL) { ns_printf(pio,"No TCP sockets\n"); return 0; } ns_printf(pio, "TCP sock, fhost, ports, opts, rxbytes, txbytes, snd_una, snd_nxt, state:\n"); for (inp = tcb.inp_next; inp != &tcb; inp = inp->inp_next) { tp = intotcpcb(inp); so = inp->inp_socket; if (!so) { ns_printf(pio,"No socket\n"); continue; } #ifdef IP_V4 if(so->so_domain == AF_INET) ns_printf(pio,"%lx, %u.%u.%u.%u", so, PUSH_IPADDR(inp->inp_faddr.s_addr)); #endif #ifdef IP_V6 if(so->so_domain == AF_INET6) { char ip6buf[46]; ns_printf(pio,"%lx, %s(v6), ", so, print_ip6(&inp->ip6_faddr, &ip6buf[0])); } #endif /* IP_V6 */ ns_printf(pio,", %u->%u, ", htons(inp->inp_lport), htons(inp->inp_fport)); ns_printf(pio,"0x%x, %u, %u, %ld, %ld, ", (unsigned)so->so_options, (unsigned)so->so_rcv.sb_cc,(unsigned)so->so_snd.sb_cc, tp->snd_una, tp->snd_nxt); if ((tp->t_state < 0) || (tp->t_state >= sizeof(tcpstates)/sizeof(tcpstates[0]))) ns_printf(pio, "???\n"); else ns_printf(pio, "%s\n", tcpstates[tp->t_state]); } return udpsock_list(pio); }
int tfc_done(int status, struct tfconn *cn, char *msg) { ip_addr fhost = cn->tf_fhost; unsigned dir = cn->tf_dir; ns_printf(last_pio, "tftp %s %u.%u.%u.%u done; ", (dir == PUT) ? "to" : "from", PUSH_IPADDR(fhost)); ns_printf(last_pio, "msg: %s, status:%s(%d)\n", msg ? msg : "None", (status == 0) ? "ok" : "error", status); last_pio = NULL; /* clear this - default back to console */ return 0; }
int upnp_stats(void * pio) { int i; ns_printf(pio, "UPnP stats:\n"); for(i = 0; i < MAXNETS; i++) { if(nets[i] == NULL) break; ns_printf(pio, "iface %s; state:%s; current IP:%u.%u.%u.%u\n", nets[i]->name, upnp_states[upnp[i].state], PUSH_IPADDR(nets[i]->n_ipaddr)); } return 0; }
int tfs_done(int status, struct tfconn * cn, char * msg) { ip_addr fhost = cn->tf_fhost; unsigned dir = cn->tf_dir; if (status == 0) { ns_printf(NULL, "tftp server: moved %lu bytes %s ", cn->tf_size, (dir==PUT) ? "to" : "from"); } else /* error of some kind */ { ns_printf(NULL, "tftp server error: status %d, msg: %s, host:", status, (msg) ? msg : "None"); } ns_printf(NULL, "%u.%u.%u.%u\n", PUSH_IPADDR(fhost)); return 0; }
int tftp_state(void *pio) { struct tfconn * cn; int nconns = 0; #ifdef TFTP_SERVER ns_printf(pio, "tftp server state %s\n", tftp_server_on?"ON":"OFF"); #endif /* TFTP_SERVER */ for (cn = tftp_conns; cn; cn = cn->next) { ns_printf(pio, "connection: %s %u.%u.%u.%u, state:%d, bytes moved: %ld \n", cn->tf_dir==PUT?"put to":"get from", PUSH_IPADDR(cn->tf_fhost), cn->tf_state, cn->tf_size); nconns++; } ns_printf(pio, "%d connections open\n", nconns); return 0; }
int ping_flood(void * pio) { long i,e; ns_printf(pio, "sending ping flood of %ld pkts to %u.%u.%u.%u..", pktcount, PUSH_IPADDR(activehost) ); for (i = 0; i < pktcount; i++) { if (pktwait("ping", pio)) return -1; e = icmpEcho(activehost, NULL, deflength, (unshort)i); if (e < 0) { ns_printf(pio, "ping flood send error %d on pkt %ld\n",e,i); return -1; } if ((i & 0x0f) == 0x0f) ns_printf(pio, "."); } return 0; }
int upnp_db(void * pio) { char * cp; NET ifp; int iface; ip_addr addr; ip_addr mask; ip_addr gateway; cp = nextarg( ((GEN_IO)pio)->inbuf ); if(!*cp) { ns_printf(pio, "please enter iface for database dump\n"); return -1; } ifp = if_netbytext(pio, cp); if(ifp == NULL) /* error parsing iface name/number text? */ return -1; iface = if_netnumber(ifp); /* Get the fixed IP info from database into tmp vars */ DS_get_long(tag_NET_FIXED_IP, iface, &addr); DS_get_long(tag_NET_FIXED_SUBNET, iface, &mask); DS_get_long(tag_NET_FIXED_GATEWAY, iface, &gateway); ns_printf(pio, "iface:%s; ", ifp->name); ns_printf(pio, " Fixed IP: %u.%u.%u.%u", PUSH_IPADDR(addr) ); ns_printf(pio, " mask: %u.%u.%u.%u", PUSH_IPADDR(mask) ); ns_printf(pio, " gateway: %u.%u.%u.%u\n", PUSH_IPADDR(gateway) ); /* Get the current IP info from database into tmp vars */ DS_get_long(tag_NET_IP_ADDRESS, iface, &addr); DS_get_long(tag_NET_SUBNET, iface, &mask); DS_get_long(tag_NET_GATEWAY, iface, &gateway); ns_printf(pio, "Current ip: %u.%u.%u.%u", PUSH_IPADDR(addr)); ns_printf(pio, " mask: %u.%u.%u.%u", PUSH_IPADDR(mask)); ns_printf(pio, " gateway: %u.%u.%u.%u\n", PUSH_IPADDR(gateway)); return 0; }
/* FUNCTION: netmain_iface() * * Display interface status * * PARAM1: CLI_CTX CLI context * * RETURN: int 0 if successful, otherwise error code * * iface -i <iface> */ STATIC int netmain_iface(CLI_CTX ctx) { GIO *gio = ctx->gio; struct net *ifp; int iface; if (CLI_HELP(ctx)) { return (0); } if (CLI_DEFINED(ctx, 'i')) { iface = (int)CLI_VALUE(ctx, 'i'); if ((iface < 1) || (iface > (int)ifNumber)) return (CLI_ERR_PARAM); ifp = nets[iface - 1]; if (CLI_DEFINED(ctx, 'm')) { uint32_t mtu = (uint32_t)CLI_VALUE(ctx, 'm'); if ((mtu >= 128) && (mtu < 65536)) { ifp->n_mtu = mtu; /* new interface MTU value */ } else return (CLI_ERR_PARAM); } gio_printf(gio, "Interface %s - %s, MTU %d\n", ifp->name, ifp->n_mib->ifDescr, ifp->n_mtu); #ifdef IP_V4 gio_printf(gio, "IPv4 address: %u.%u.%u.%u, ", PUSH_IPADDR(ifp->n_ipaddr)); gio_printf(gio, "subnet mask: %u.%u.%u.%u, ", PUSH_IPADDR(ifp->snmask)); gio_printf(gio, "gateway: %u.%u.%u.%u\n", PUSH_IPADDR(ifp->n_defgw)); #endif /* IP_V4 */ { char buf[80]; gio_printf(gio, "Flags: %s\n", in_bit2str(&ifp_flags[0], ifp->n_flags, &buf[0], 80, ',')); } #if defined(IP_V6) && defined(IP6_MENUS) if (ifp->n_flags & NF_IPV6) { int i; char ip6buf[46]; /* tmp buffer for ipv6 address text */ for (i = 0; i < MAX_V6_ADDRS; i++) { if (ifp->v6addrs[i]) { gio_printf(gio, "IPv6 %6s addr: %s", v6types[i], print_ip6(&(ifp->v6addrs[i]->addr), ip6buf)); gio_printf(gio, " - %s\n", ip6addrstates[ifp->v6addrs[i]->flags & IA_STATEMASK]); } } } else gio_printf(gio, "No IPv6 addresses\n"); #endif /* IP_V6 && IP6_MENUS */ gio_printf(gio, "Status: Admin:%s Oper:%s for: %s\n", (ifp->n_mib->ifAdminStatus == 1) ? "up" : "down", (ifp->n_mib->ifOperStatus == 1) ? "up" : "down", print_uptime(TIME_SUB(sysuptime(), (ifp->n_mib->ifLastChange)))); gio_printf(gio, "rcvd: errors:%lu dropped:%lu station:%lu bcast:%lu bytes:%lu\n", ifp->n_mib->ifInErrors, ifp->n_mib->ifInDiscards, ifp->n_mib->ifInUcastPkts, ifp->n_mib->ifInNUcastPkts, ifp->n_mib->ifInOctets); gio_printf(gio, "sent: errors:%lu dropped:%lu station:%lu bcast:%lu bytes:%lu\n", ifp->n_mib->ifOutErrors, ifp->n_mib->ifOutDiscards, ifp->n_mib->ifOutUcastPkts, ifp->n_mib->ifOutNUcastPkts, ifp->n_mib->ifOutOctets); gio_printf(gio, "MAC address: "); gio_hexdump(gio, ifp->n_mib->ifPhysAddress, 6, TRUE, FALSE); gio_printf(gio, " \n"); #ifdef IP_MULTICAST /* Print any multicast addresses assigned to this iface */ #ifndef USE_IGMPV3 if (ifp->mc_list) { struct in_multi *imp; gio_printf(gio, " Multicast addresses: \n"); for (imp = ifp->mc_list; imp; imp = imp->inm_next) { #ifdef IP_V6 if (*(u_long *)&imp->ip6addr != 0x0) { char ip6buf[40]; /* tmp buffer for ipv6 address text */ gio_printf(gio, " %s\n", print_ip6(&(imp->ip6addr), ip6buf)); } else #endif /* IP_V6 */ { gio_printf(gio, " %u.%u.%u.%u\n", PUSH_IPADDR(imp->inm_addr)); } } } #else /* if USE_IGMPV3 defined*/ igmp_print_membership(ifp, gio); #endif /* USE_IGMPV3 */ #endif /* IP_MULTICAST */ } else /* list all interfaces */ { for (iface = 1; iface <= (int)ifNumber; iface++) { gio_printf(gio, "%2d: %s - %s\n", iface, nets[iface-1]->name, nets[iface-1]->n_mib->ifDescr); } } return (0); }
int arp_flood (void * pio) { PACKET arppkt; struct ethhdr * ethhdr; struct arp_hdr * arphdr; NET net; long i; int e; ip_addr ipaddr; #ifdef MULTI_HOMED ip_addr phost; /* phoney host for pass to iproute */ net = iproute(activehost, &phost); #else net = nets[0]; #endif if (!net) { ns_printf(pio, "ARP flood: no route"); return -1; } ns_printf(pio, "sending ARP flood of %ld pkts to %u.%u.%u.%u..", pktcount, PUSH_IPADDR(activehost) ); for (i = 0; i < pktcount; i++) { if (pktwait("ARP", pio)) return -1; /******** code cribbed from et_arp.c: ********/ LOCK_NET_RESOURCE(FREEQ_RESID); arppkt = pk_alloc(arpsize); UNLOCK_NET_RESOURCE(FREEQ_RESID); if (!arppkt) return ENP_RESOURCE; arppkt->nb_prot = arppkt->nb_buff; arppkt->nb_plen = arpsize; arppkt->net = net; /* build arp request packet */ ethhdr = (struct ethhdr *)(arppkt->nb_buff + ETHHDR_BIAS); /* ethernet header at start of buffer */ arphdr = (struct arp_hdr *)(arppkt->nb_buff + ETHHDR_SIZE); /* arp header follows */ arphdr->ar_hd = ARPHW; /* net endian arp hardware type (ethernet) */ arphdr->ar_pro = ARPIP; arphdr->ar_hln = 6; arphdr->ar_pln = 4; arphdr->ar_op = ARREQ; arphdr->ar_tpa = activehost; /* target's IP address */ /* FLOOD TEST MOD: just for grins, rotate our IP address so we * flood everybody's arp tables. Remember that we store IP * addresses */ ipaddr = i & (0x00FFFFFE & htonl(~net->snmask)); /* make host portion */ arphdr->ar_spa = (net->n_ipaddr | htonl(ipaddr)); /* add net portion */ MEMCPY(arphdr->ar_sha, net->n_mib->ifPhysAddress, 6); MEMSET(&(ethhdr->e_dst[0]), 0xFF, 6); /* destination to broadcast (all FFs) */ MEMCPY(ethhdr->e_src, net->n_mib->ifPhysAddress, 6); ethhdr->e_type = ET_ARP; /* 0x0806 - ARP type on ethernet */ #ifdef NO_CC_PACKING /* move ARP fields to proper network boundaries */ { struct arp_wire * arwp = (struct arp_wire *)arphdr; MEMMOVE(&arwp->data[AR_SHA], arphdr->ar_sha, 6); MEMMOVE(&arwp->data[AR_SPA], &arphdr->ar_spa, 4); MEMMOVE(&arwp->data[AR_THA], arphdr->ar_tha, 6); MEMMOVE(&arwp->data[AR_TPA], &arphdr->ar_tpa, 4); } #endif /* NO_CC_PACKING */ /* send arp request - if a packet oriented send exists, use it: */ if (net->pkt_send) e = net->pkt_send(arppkt); /* driver should free arppkt later */ else /* use old raw send */ { e = net->raw_send(arppkt->net, arppkt->nb_buff, arpsize); LOCK_NET_RESOURCE(FREEQ_RESID); pk_free(arppkt); UNLOCK_NET_RESOURCE(FREEQ_RESID); } arpReqsOut++; /******** end of code cribbed from et_arp.c: ********/ if (e < 0) { ns_printf(pio, "ARP flood send error %d on pkt %ld\n",e,i); return -1; } if ((i & 0x0f) == 0x0f) ns_printf(pio, "."); } return 0; }
/* FUNCTION: netdiag_dnssvr() * * Add/delete an entry in the remote DNS server table. * If -i and -a, set the 'i'th entry to IP address 'a'. * If -a, set the next unused entry to IP address 'a'. * If -i and -d, reset the 'i'th entry to zero. * If no params, display the current DNS table. * * PARAM1: CLI_CTX CLI context * * RETURN: int success or error code */ STATIC int netdiag_dnssvr(CLI_CTX ctx) { GIO *gio = ctx->gio; unsigned int idx; int count = 0; if (!CLI_HELP(ctx) && (CLI_DEFINED(ctx, 'a') || CLI_DEFINED(ctx, 'd'))) { /* -a and -d are mutually exclusive */ if (CLI_DEFINED(ctx, 'a') && CLI_DEFINED(ctx, 'd')) return (CLI_ERR_PARAM); if (CLI_DEFINED(ctx, 'a')) /* add an entry */ { struct cli_addr *ipaddr = (struct cli_addr *)CLI_VALUE(ctx, 'a'); /* if the caller specified an index, use it * otherwise look for the first available slot */ if (CLI_DEFINED(ctx, 'i')) { idx = (unsigned int)CLI_VALUE(ctx, 'i') - 1; } else { for (idx = 0; idx < MAXDNSSERVERS; idx++) { if (dns_servers[idx] == 0) break; } } /* if the index is in range and the IP address is valid, * add/update an entry in the DNS server address table */ if ((idx < MAXDNSSERVERS) && (ipaddr->type == CLI_IPV4)) dns_servers[idx] = *(ip_addr *)&ipaddr->addr; else return (CLI_ERR_PARAM); } else if (CLI_DEFINED(ctx, 'd')) /* delete an entry */ { idx = (CLI_DEFINED(ctx, 'i') ? ((unsigned int)CLI_VALUE(ctx, 'i') - 1) : MAXDNSSERVERS); if (idx < MAXDNSSERVERS) { /* delete an entry from the DNS server address table */ /* compress the table */ for ( ; idx < (MAXDNSSERVERS-1); idx++) { dns_servers[idx] = dns_servers[idx+1]; } dns_servers[idx] = 0; } else return (CLI_ERR_PARAM); } } /* now dump the table */ gio_printf(gio, "DNS servers:"); for (idx = 0; idx < MAXDNSSERVERS; idx++) { if (dns_servers[idx] != 0) { gio_printf(gio, " %u.%u.%u.%u ", PUSH_IPADDR(dns_servers[idx])); count++; } } gio_printf(gio, "%s\n", (count == 0) ? " none" : ""); return (0); }
int flood_addr(void * pio) { char * cp = nextarg(((GEN_IO)pio)->inbuf); char arg; /* first char of second arg - a, d, or l. */ char * hosttext; ip_addr host; unsigned i; if (!*cp) /* no arg given */ goto fa_usage; arg = ((*cp) | 0x40); /* force arg to lowercase */ if(arg == 'l') /* user wants list */ { ns_printf(pio, "Current flood target list:\n"); for(i = 0; i < MAXFLOODTARGETS; i++) { if (floodtargs[i] == 0) break; ns_printf(pio, "%u.%u.%u.%u\n", PUSH_IPADDR(floodtargs[i])); } return 0; } /* make sure arg is 'a' or 'd' ('l' is handled above */ if((arg != 'a') && (arg != 'd')) { ns_printf(pio, "Arg must begin with 'a' or 'd'\n"); goto fa_usage; } hosttext = nextarg(cp); if(!(*hosttext)) goto fa_usage; cp = parse_ipad(&host, &i, hosttext); if(cp) { ns_printf(pio, "%s\n", cp); goto fa_usage; } for(i = 0; i < MAXFLOODTARGETS; i++) { if((arg == 'a') && (floodtargs[i] == 0)) { floodtargs[i] = host; ns_printf(pio, "Added host %u.%u.%u.%u\n", PUSH_IPADDR(host)); return 0; } if((arg == 'd') && (floodtargs[i] == host)) { floodtargs[i] = 0; ns_printf(pio, "Deleted host %u.%u.%u.%u\n", PUSH_IPADDR(host)); for( ; i < (MAXFLOODTARGETS - 1); i++) /* move up rest of list */ floodtargs[i] = floodtargs[i + 1]; floodtargs[i] = 0; /* clear last entry */ return 0; } } ns_printf(pio, "Sorry, %s\n", arg=='a'?"flood target table full":"Host not in list"); return -1; fa_usage: ns_printf(pio, "Usage: faddr <add|delete|list> X.X.X.X\n"); return -1; }
void nv_defaults() { int iface = 0; VFILE *fp; int e; /* store default IP info */ #ifdef USE_SMSC91X inet_nvparms.ifs[iface].ipaddr = htonl(0x0a000067); /* 10.0.0.106 */ #ifdef USE_PPPOE inet_nvparms.ifs[iface].subnet = htonl(0xfffe0000); /* 255.254.0.0 */ inet_nvparms.ifs[iface].gateway = htonl(0x00000000); /* 0.0.0.0 */ #else inet_nvparms.ifs[iface].subnet = htonl(0xff000000); /* 255.0.0.0 */ inet_nvparms.ifs[iface].gateway = htonl(0x0a000001); /* 10.0.0.1 */ #endif inet_nvparms.ifs[iface].client_dhcp = 0; dprintf("nv_defaults: set net %d IP to %u.%u.%u.%u\n", iface, PUSH_IPADDR(inet_nvparms.ifs[iface].ipaddr) ); iface++; #endif /* */ #ifdef USE_PPP /* PPP */ inet_nvparms.ifs[iface].ipaddr = htonl(0x00000000); inet_nvparms.ifs[iface].subnet = htonl(0xffffff00); /* 255.255.255.0 */ inet_nvparms.ifs[iface].gateway = htonl(0xc0a80801); /* 192.168.8.1 */ iface++; #ifdef LB_XOVER inet_nvparms.ifs[iface].ipaddr = htonl(0x00000000); inet_nvparms.ifs[iface].subnet = htonl(0x00000000); inet_nvparms.ifs[iface].gateway = htonl(0x00000000); iface++; #endif /* LB_XOVER */ #endif /* USE_PPP */ /* loopback */ inet_nvparms.ifs[iface].ipaddr = htonl(0x00000000); inet_nvparms.ifs[iface].subnet = htonl(0x00000000); inet_nvparms.ifs[iface].gateway = htonl(0x00000000); #ifdef USE_COMPORT comport_nvparms.LineProtocol = 1; #endif /* defined (USE_PPP) || defined(USE_SLIP) */ #ifdef USE_PPP ppp_nvparms.ppp_ConsoleLog = 0; /* Log Modem & PPP events to console */ ppp_nvparms.ppp_FileLog = 0; /* Log Modem & PPP events to file */ ppp_nvparms.ppp_keepalive = 0; /* seconds between PPP echos, 0=disable */ ppp_nvparms.ppp_client_tmo = 500; /* timeout for connects as client */ ppp_nvparms.line_tmo = 300; #ifdef PPP_VJC ppp_nvparms.ppp_request_vj = 1; /* request that the other side do VJ compression */ #endif /* PPP_VJC */ #ifdef PAP_SUPPORT ppp_nvparms.require_pap = 0; #endif /* PAP_SUPPORT */ #ifdef USE_PPPOE strcpy(ppp_nvparms.username, "ppptest2"); strcpy(ppp_nvparms.password, "2ppptest"); strcpy(ppp_nvparms.secret, "2ppptest"); #endif /* USE_PPPOE */ #endif /* USE_PPP */ #ifdef USE_MODEM strcpy(modem_nvparms.dial_phone, "YOUR_ISP_PHONE\n"); strcpy(ppp_nvparms.username, "YOUR_ISP_NAME"); strcpy(ppp_nvparms.password, "YOUR_ISP_PASSWORD"); strcpy(modem_nvparms.modem_init, "AT&D0&C1\n"); strcpy(ppp_nvparms.loginfile, logfilename); strcpy(ppp_nvparms.logservefile, srvfilename); #endif /* USE_MODEM */ #ifdef USE_COMPORT comport_nvparms.comport = '2'; comport_nvparms.LineProtocol = 1; #endif /* USE_COMPORT */ #ifdef NATRT natrt_nvparms.nat_enabled = 1; natrt_nvparms.nat_inet = 1; natrt_nvparms.nat_localnet = 0; natrt_nvparms.tcp_timeout = 300; natrt_nvparms.udp_timeout = 500; #endif /* NATRT */ #ifdef SMTP_ALERTS smtp_nvparms.mserver = htonl(0x00000000); strcpy(smtp_nvparms.rcpt, "\n"); #endif /* SMTP_ALERTS */ #ifdef DNS_CLIENT_UPDT strcpy(inet_nvparms.dns_zone_name, "iniche.com"); /* zone name */ #endif /* DNS_CLIENT_UPDT */ /* create the login script file */ fp = nv_fopen(logfilename, "w+"); if (fp == NULL) dprintf("error creating %s\n", logfilename); else { e = nv_fprintf(fp, "#\n#empty login.nv\n#\n"); if (e < 1) { dprintf("nv_defaults: error writing %s\n", logfilename); } nv_fclose(fp); } /* create the some required NV files */ nv_fopen(srvfilename, "w+"); nv_fopen(natfilename, "w+"); }
int in_reshost(char * host, /* IN - textual IP address or host name */ ip_addr * address, /* OUT - address if successful */ int flags) /* IN - RH_VERBOSE, RH_BLOCK */ { char * cp; /* error holder */ unsigned snbits; /* for pass to parse_ipad() */ #ifdef DNS_CLIENT int e; /* Net error code */ u_long tmo; /* timeout for blocking calls */ int blocking = flags & RH_BLOCK; #endif /* DNS_CLIENT */ int verbose = flags & RH_VERBOSE; cp = parse_ipad(address, &snbits, host); if (!cp) /* worked, string was parsable dot notation */ return 0; #ifndef DNS_CLIENT if (verbose) dprintf("Unable to parse IP host %s.\nerror: %s\n", host, (char*)cp); return ENP_PARAM; #else /* DNS_CLIENT enabled in build */ if (verbose) dprintf("can't parse %s (%s), trying DNS\n", host, cp); tmo = cticks + (5 * TPS); /* set timeout value */ if (dns_servers[0]) /* dont bother if no servers are set */ { if (verbose) dprintf("trying DNS lookup...\n"); e = dns_query(host, address); if (e == ENP_SEND_PENDING) { if (blocking) { while (tmo > cticks) { tk_yield(); e = dns_query(host, address); if (e == 0) goto rh_got_dns; } } if (verbose) dprintf("DNS inquiry sent\n"); return 0; } else if(e == 0) { rh_got_dns: /* DNS resolution worked */ if (verbose) dprintf("active host found via DNS (%u.%u.%u.%u)\n", PUSH_IPADDR(*address)); return 0; } else if(e == ENP_TIMEOUT) /* timeout? */ { if (verbose) dprintf("DNS timeout"); } else { if (verbose) dprintf("DNS error %d", e); } if (verbose) dprintf(", host not set\n"); return e; } if (verbose) dprintf("DNS/host-parse failed.\n"); return ENP_PARAM; #endif /* DNS_CLIENT */ }