static int update(pkt_t *pkt, void *fh, int isnew) { FLOWDESC *x = F(fh); if (isnew) { x->ts = TS2SEC(pkt->ts); x->bytes = 0; x->pkts = 0; x->proto = IP(proto); x->src_ip = IP(src_ip); x->dst_ip = IP(dst_ip); N16(x->src_port) = N16(x->dst_port) = 0; if (IP(proto) == IPPROTO_TCP || IP(proto) == IPPROTO_UDP) { x->src_port = UDP(src_port); x->dst_port = UDP(dst_port); } } x->bytes += H16(IP(len)); x->pkts++; return 0; }
/* ************************************************ * this function is the entry point for kernel * debuging. It is called by xokpkt_recv in pkt.h * It is assumed that data "kdebug_is_debug_pkt". * *************************************************/ void kdebug_pkt (char *data, int size) { int i, min; char c; assert (kdebug_didinit); if(!kdebug_return_didinit) { kdebug_return_init(data); if (!in_exception_handler) { asm("int $3"); /* * When you connnect to the target from gdb * you end up here. */ asm("nop"); /* Now, set the brkpts you want and continue. */ } } /* the udp_len field might lie, so must be careful */ min = MIN(ntohs(UDP(data)->udp_len) - 8, size - 14 - 20 - 8); for (i=0 ; i < min; i++) { char c = UDP(data)->udp_data[i]; if (c == '\003' && !in_exception_handler) asm ("int $3"); /* you end up here if you typed Ctrl-C, into gdb */ else enq(c); } }
static int update(pkt_t *pkt, void *fh, int isnew) { FLOWDESC *x = F(fh); if (isnew) { x->nts = 0; x->proto = IP(proto); x->src_ip = IP(src_ip); x->dst_ip = IP(dst_ip); if (IP(proto) == IPPROTO_TCP) { x->src_port = TCP(src_port); x->dst_port = TCP(dst_port); } else if (IP(proto) == IPPROTO_UDP) { x->src_port = UDP(src_port); x->dst_port = UDP(dst_port); } else { N16(x->src_port) = N16(x->dst_port) = 0; } } x->ts[x->nts] = pkt->ts; x->nts++; if (x->nts == 10) return 1; else return 0; }
static uint32_t hash(pkt_t *pkt) { uint sport, dport; sport = dport = 0; if (IP(proto) == IPPROTO_TCP || IP(proto) == IPPROTO_UDP) { sport = N16(UDP(src_port)); dport = N16(UDP(dst_port)); } return (N32(IP(src_ip)) ^ N32(IP(dst_ip)) ^ (sport << 3) ^ (dport << 3)); }
bool MTD_FLASHMEM SNTPClient::query(uint64_t* outValue) const { // send req (mode 3), unicast, version 4 uint8_t const MODE_CLIENT = 3; uint8_t const VERSION = 4; uint8_t const BUFLEN = 48; uint32_t const REPLYTIMEOUT = 3000; uint8_t buf[BUFLEN]; memset(&buf[0], 0, BUFLEN); buf[0] = MODE_CLIENT | (VERSION << 3); UDPClient UDP(m_server, m_port); Socket* socket = UDP.getSocket(); socket->setTimeOut(REPLYTIMEOUT); if (socket->write(&buf[0], BUFLEN)) { // get reply if (socket->read(&buf[0], BUFLEN) == BUFLEN) { memcpy(outValue, &buf[40], sizeof(uint64_t)); return true; // ok } } return false; // error }
static uint32_t hash(pkt_t *pkt) { uint sport, dport; if (IP(proto) == IPPROTO_TCP) { sport = N16(TCP(src_port)); dport = N16(TCP(dst_port)); } else if (IP(proto) == IPPROTO_UDP) { sport = N16(UDP(src_port)); dport = N16(UDP(dst_port)); } else { sport = dport = 0; } /* The hash is a bitwise XOR of IP addresses and ports */ return (N32(IP(src_ip)) ^ N32(IP(dst_ip)) ^ (sport << 3) ^ (dport << 3)); }
static int match(pkt_t *pkt, void *fh) { FLOWDESC *x = F(fh); uint sport, dport; sport = dport = 0; if (IP(proto) == IPPROTO_TCP || IP(proto) == IPPROTO_UDP) { sport = N16(UDP(src_port)); dport = N16(UDP(dst_port)); } return ( N32(IP(src_ip)) == N32(x->src_ip) && N32(IP(dst_ip)) == N32(x->dst_ip) && sport == N16(x->src_port) && dport == N16(x->dst_port) && IP(proto) == x->proto ); }
void capture(mdl_t *self, pkt_t *pkt, tuple_t *st, double srate) { config_t *config = mdl_get_config(self, config_t); int app, app1, app2; double b, p; if (! isTCP && ! isUDP) /* non-TCP, non-UDP traffic */ app = 1; else { /* TCP and UDP traffic */ if (isTCP) { app1 = config->tcp_port2app[H16(TCP(src_port))]; app2 = config->tcp_port2app[H16(TCP(dst_port))]; } else { app1 = config->udp_port2app[H16(UDP(src_port))]; app2 = config->tcp_port2app[H16(UDP(dst_port))]; } if (app1 == 0 || app2 == 0) /* at most 1 port matches a known app */ app = app1 + app2; else if (app1 == app2) /* both ports match the same app */ app = app1; else /* ports match different apps, unknown */ app = 0; } if (COMO(type) == COMOTYPE_NF) { b = H32(NF(pktcount)) * COMO(len) * H16(NF(sampling)); p = H32(NF(pktcount)) * (uint32_t) H16(NF(sampling)); } else if (COMO(type) == COMOTYPE_SFLOW) { b = (uint64_t) COMO(len) * (uint64_t) H32(SFLOW(sampling_rate)); p = H32(SFLOW(sampling_rate)); } else { b = COMO(len); p = 1; } /* scale with sampling rate */ st->bytes[app] += b / srate; st->pkts[app] += p / srate; }
int kdebug_is_debug_pkt(const char *data, int size) { /* * check that packet is an IP pkt contain an UDP packet * whose destination port is KDEBUG_PORT */ return ((size >= ETHER_MIN_LEN) && (size <= ETHER_MAX_LEN) && (ntohs(ETHER(data)->ether_type) == ETHERTYPE_IP) && (IP(data)->ip_p == IPPROTO_UDP) && (ntohs(UDP(data)->udp_dport) == KDEBUG_PORT)); }