From 4718fca0b0f0f2f84f36f933ca127372baf1d3a8 Mon Sep 17 00:00:00 2001 From: Teguh Date: Tue, 9 Oct 2012 04:58:51 +0700 Subject: [PATCH] rollback --- src/flowtop.c | 25 +++++++++++++------------ src/hextools.c | 10 +++++++--- src/ifpps.c | 9 ++++++--- src/layer3.c | 19 +++++++++++++------ src/mops.c | 8 ++++---- src/mops_ext_igmp.c | 9 +++++---- src/pcap_mmap.c | 3 ++- src/proto_80211_mac_hdr.c | 7 +++---- src/rcv_rtp.c | 10 +++++----- src/xutils.c | 9 ++++----- 10 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/flowtop.c b/src/flowtop.c index 8006255c..6f2fc6a8 100644 --- a/src/flowtop.c +++ b/src/flowtop.c @@ -516,9 +516,6 @@ static int get_inode_from_local_port(int port, const char *proto, int ip6) static void flow_entry_from_ct(struct flow_entry *n, struct nf_conntrack *ct) { - const uint8_t *ipv6_src = nfct_get_attr(ct, ATTR_ORIG_IPV6_SRC); - const uint8_t *ipv6_dst = nfct_get_attr(ct, ATTR_ORIG_IPV6_DST); - n->flow_id = nfct_get_attr_u32(ct, ATTR_ID); n->use = nfct_get_attr_u32(ct, ATTR_USE); n->status = nfct_get_attr_u32(ct, ATTR_STATUS); @@ -527,8 +524,10 @@ static void flow_entry_from_ct(struct flow_entry *n, struct nf_conntrack *ct) n->ip4_src_addr = nfct_get_attr_u32(ct, ATTR_ORIG_IPV4_SRC); n->ip4_dst_addr = nfct_get_attr_u32(ct, ATTR_ORIG_IPV4_DST); + const uint8_t *ipv6_src = nfct_get_attr(ct, ATTR_ORIG_IPV6_SRC); if (ipv6_src) memcpy(n->ip6_src_addr, ipv6_src, sizeof(n->ip6_src_addr)); + const uint8_t *ipv6_dst = nfct_get_attr(ct, ATTR_ORIG_IPV6_DST); if (ipv6_dst) memcpy(n->ip6_dst_addr, ipv6_dst, sizeof(n->ip6_dst_addr)); @@ -747,14 +746,6 @@ static void *collector(void *null) u_int32_t family = AF_INET; struct nfct_handle *handle; struct nfct_filter *filter; - struct nfct_filter_ipv4 filter_ipv4 = { - .addr = ntohl(INADDR_LOOPBACK), - .mask = 0xffffffff, - }; - struct nfct_filter_ipv6 filter_ipv6 = { - .addr = { 0x0, 0x0, 0x0, 0x1 }, - .mask = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, - }; handle = nfct_open(CONNTRACK, NFCT_ALL_CT_GROUPS); if (!handle) @@ -779,10 +770,19 @@ static void *collector(void *null) if (what & INCLUDE_TCP) nfct_filter_add_attr_u32(filter, NFCT_FILTER_L4PROTO, IPPROTO_TCP); + struct nfct_filter_ipv4 filter_ipv4 = { + .addr = ntohl(INADDR_LOOPBACK), + .mask = 0xffffffff, + }; nfct_filter_set_logic(filter, NFCT_FILTER_SRC_IPV4, NFCT_FILTER_LOGIC_NEGATIVE); - nfct_filter_add_attr(filter, NFCT_FILTER_SRC_IPV4, &filter_ipv4); + nfct_filter_add_attr(filter, NFCT_FILTER_SRC_IPV4, &filter_ipv4); + + struct nfct_filter_ipv6 filter_ipv6 = { + .addr = { 0x0, 0x0, 0x0, 0x1 }, + .mask = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, + }; nfct_filter_set_logic(filter, NFCT_FILTER_SRC_IPV6, NFCT_FILTER_LOGIC_NEGATIVE); @@ -899,3 +899,4 @@ int main(int argc, char **argv) return 0; } + diff --git a/src/hextools.c b/src/hextools.c index 151b7fae..09261587 100644 --- a/src/hextools.c +++ b/src/hextools.c @@ -87,10 +87,12 @@ int str2hex(char* str, u_int8_t *hp, int n) { char *hs; int curval,i; - char tmp[8192]=""; //for very long payloads + if (strlen(str)==0) return 0; + char tmp[8192]=""; //for very long payloads + strncpy(tmp,str,8191); // necessary because strtok cannot operate on fixed strings hs=(char*)strtok(tmp,"-:., "); @@ -120,9 +122,10 @@ int num2hex(char* str, u_int8_t *hp) char *hs; int i; unsigned int curval; - char tmp[8192]=""; //for very long payloads if (strlen(str)==0) return 0; + + char tmp[8192]=""; //for very long payloads strncpy(tmp,str,8192); // necessary because strtok cannot operate on fixed strings @@ -273,7 +276,7 @@ u_int32_t str2ip32_rev (char* str) int type2str(u_int16_t type, char *str) { char hex[8]; - int i; + int i=0; (void) sprintf (hex, "%x",type); i=strlen(hex); @@ -317,3 +320,4 @@ int type2str(u_int16_t type, char *str) return i; } + diff --git a/src/ifpps.c b/src/ifpps.c index 54e9813f..e9750e6c 100644 --- a/src/ifpps.c +++ b/src/ifpps.c @@ -410,12 +410,11 @@ static int irq_stats(const char *ifname, struct ifstat *s) char *ptr, *ptr2; char buff[4096]; - FILE *fp = fopen("/proc/interrupts", "r"); - /* We exclude lo! */ if (!strncmp("lo", ifname, strlen("lo"))) return 0; + FILE *fp = fopen("/proc/interrupts", "r"); if (!fp) { whine("Cannot open /proc/interrupts!\n"); return -ENOENT; @@ -894,7 +893,10 @@ int main(int argc, char **argv) panic("This is no networking device!\n"); register_signal(SIGINT, signal_handler); register_signal(SIGHUP, signal_handler); - + if (promisc) { + check_for_root_maybe_die(); + ifflags = enter_promiscuous_mode(ifname); + } ret = main_loop(ifname, interval); if (promisc) leave_promiscuous_mode(ifname, ifflags); @@ -903,3 +905,4 @@ int main(int argc, char **argv) return ret; } + diff --git a/src/layer3.c b/src/layer3.c index f3fa7d26..6b005ba2 100644 --- a/src/layer3.c +++ b/src/layer3.c @@ -144,9 +144,6 @@ libnet_ptag_t create_ip_packet (libnet_t *l) libnet_ptag_t t; char argval[MAX_PAYLOAD_SIZE]; int i, T; // only an abbreviation for tx.packet_mode - unsigned int dummy; - size_t len; - char *s; if (ipv6_mode) return create_ip6_packet(l); @@ -158,6 +155,13 @@ libnet_ptag_t create_ip_packet (libnet_t *l) tx.ip_sum = 0; // default: automatically calculate checksum tx.ip_tos = 0; tx.ip_ttl = 255; + + + // temporary variables + unsigned int dummy; + size_t len; + char *s; + T = tx.packet_mode; // >0 means automatic L2 creation @@ -457,9 +461,6 @@ libnet_ptag_t create_ip6_packet (libnet_t *l) libnet_ptag_t t; char argval[MAX_PAYLOAD_SIZE]; int i, T; // only an abbreviation for tx.packet_mode - unsigned int dummy; - size_t len; - char *s; // Default IP header fields tx.ip_len = 0; @@ -471,6 +472,11 @@ libnet_ptag_t create_ip6_packet (libnet_t *l) tx.ip_tos = 0; tx.ip_ttl = 255; + // temporary variables + unsigned int dummy; + size_t len; + char *s; + T = tx.packet_mode; // >0 means automatic L2 creation if ( (getarg(tx.arg_string,"help", NULL)==1) && (mode==IP) ) @@ -726,3 +732,4 @@ libnet_ptag_t create_ip6_packet (libnet_t *l) return t; } + diff --git a/src/mops.c b/src/mops.c index 02e846f8..7b3b2183 100644 --- a/src/mops.c +++ b/src/mops.c @@ -54,13 +54,12 @@ // struct mops * mops_init() { - // Create initial mops element: - struct mops *new_mops = (struct mops*) malloc(sizeof(struct mops)); - // these defaults can be changed by the user: min_frame_s = MIN_MOPS_FRAME_SIZE; // important global; depends on used packet tx subsystem such as libnet max_frame_s = MAX_MOPS_FRAME_SIZE-MOPS_SIZE_MARGIN; - + + // Create initial mops element: + struct mops *new_mops = (struct mops*) malloc(sizeof(struct mops)); new_mops->next = new_mops; new_mops->prev = new_mops; new_mops->state = MOPS_STATE_NULL; @@ -768,3 +767,4 @@ int mops_get_proto_info(struct mops *mp, char *layers, char *proto) } + diff --git a/src/mops_ext_igmp.c b/src/mops_ext_igmp.c index 69d98c4a..e8b91f7f 100644 --- a/src/mops_ext_igmp.c +++ b/src/mops_ext_igmp.c @@ -139,12 +139,12 @@ int mops_create_igmpv2 (struct mops *mp, int mops_update_igmp (struct mops * mp) { - - struct mops_ext_igmp * pd; - pd = mp->p_desc; + struct mops_ext_igmp * pd; + + pd = mp->p_desc; + if (pd==NULL) return 1; // no valid pointer to a p_desc mp->msg_s = 0; // important! Otherwise the msg would get longer and longer after each call! u_int16_t sum; - if (pd==NULL) return 1; // no valid pointer to a p_desc switch (pd->version) { @@ -268,3 +268,4 @@ int mops_update_igmp (struct mops * mp) // // // + diff --git a/src/pcap_mmap.c b/src/pcap_mmap.c index e60c73a9..ffed817b 100644 --- a/src/pcap_mmap.c +++ b/src/pcap_mmap.c @@ -233,9 +233,9 @@ static void pcap_mmap_fsync_pcap(int fd) static void pcap_mmap_prepare_close_pcap(int fd, enum pcap_mode mode) { + spinlock_lock(&lock); int ret = munmap(pstart, map_size); - spinlock_lock(&lock); if (ret < 0) panic("Cannot unmap the pcap file!\n"); @@ -276,3 +276,4 @@ void cleanup_pcap_mmap(void) pcap_ops_group_unregister(PCAP_OPS_MMAP); } + diff --git a/src/proto_80211_mac_hdr.c b/src/proto_80211_mac_hdr.c index e9a7a9c3..269706b6 100644 --- a/src/proto_80211_mac_hdr.c +++ b/src/proto_80211_mac_hdr.c @@ -307,16 +307,14 @@ static char *mgt_sub(u8 subtype, struct pkt_buff *pkt, int8_t (**get_content)(st struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) pkt_pull(pkt, sizeof(*mgmt)); + if (mgmt == NULL) + return 0; const char *dst = lookup_vendor((mgmt->da[0] << 16) | (mgmt->da[1] << 8) | mgmt->da[2]); const char *src = lookup_vendor((mgmt->sa[0] << 16) | (mgmt->sa[1] << 8) | mgmt->sa[2]); const char *bssid = lookup_vendor((mgmt->bssid[0] << 16) | (mgmt->bssid[1] << 8) | mgmt->bssid[2]); - u16 seq_ctrl = le16_to_cpu(mgmt->seq_ctrl); - if (mgmt == NULL) - return 0; - tprintf("Duration (%u),", le16_to_cpu(mgmt->duration)); tprintf("\n\tDestination (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ", mgmt->da[0], mgmt->da[1], mgmt->da[2], mgmt->da[3], mgmt->da[4], mgmt->da[5]); @@ -510,3 +508,4 @@ struct protocol ieee80211_ops = { }; EXPORT_SYMBOL(ieee80211_ops); + diff --git a/src/rcv_rtp.c b/src/rcv_rtp.c index 8622eb79..8789c1f1 100644 --- a/src/rcv_rtp.c +++ b/src/rcv_rtp.c @@ -375,11 +375,6 @@ void got_rtp_packet(u_char *args, int size_ethernet = sizeof(struct struct_ethernet); int size_ip = sizeof(struct struct_ip); int size_udp = sizeof(struct struct_udp); - - struct mz_timestamp - deltaTX, - deltaRX; - // int size_rtp = sizeof(struct struct_rtp); // ethernet = (struct struct_ethernet*)(packet); @@ -387,6 +382,10 @@ void got_rtp_packet(u_char *args, udp = (struct struct_udp*)(packet+size_ethernet+size_ip); rtp = (struct struct_rtp*)(packet+size_ethernet+size_ip+size_udp); + struct mz_timestamp + deltaTX, + deltaRX; + u_int32_t i, jitter_abs, @@ -768,3 +767,4 @@ void print_jitterbar (long int j, u_int32_t d) fprintf(stdout,"%s\n", bar); } + diff --git a/src/xutils.c b/src/xutils.c index b7a78689..c2c0c74a 100644 --- a/src/xutils.c +++ b/src/xutils.c @@ -557,12 +557,11 @@ int device_irq_number(const char *ifname) char *buffp; char buff[512]; char sysname[512]; - - FILE *fp = fopen("/proc/interrupts", "r"); if (!strncmp("lo", ifname, strlen("lo"))) return 0; + FILE *fp = fopen("/proc/interrupts", "r"); if (!fp) { whine("Cannot open /proc/interrupts!\n"); return -ENOENT; @@ -615,8 +614,6 @@ int device_bind_irq_to_cpu(int irq, int cpu) int ret; char buff[256]; char file[256]; - - FILE *fp = fopen(file, "w"); /* Note: first CPU begins with CPU 0 */ if (irq < 0 || cpu < 0) @@ -629,6 +626,7 @@ int device_bind_irq_to_cpu(int irq, int cpu) cpu = cpu + 1; sprintf(file, "/proc/irq/%d/smp_affinity", irq); + FILE *fp = fopen(file, "w"); if (!fp) { whine("Cannot open file %s!\n", file); return -ENOENT; @@ -698,8 +696,8 @@ int get_tty_size(void) return (ret == 0 ? ts.ts_cols : DEFAULT_TTY_SIZE); #elif defined(TIOCGWINSZ) struct winsize ts; - int ret = ioctl(0, TIOCGWINSZ, &ts); memset(&ts, 0, sizeof(ts)); + int ret = ioctl(0, TIOCGWINSZ, &ts); return (ret == 0 ? ts.ws_col : DEFAULT_TTY_SIZE); #else return DEFAULT_TTY_SIZE; @@ -1061,3 +1059,4 @@ char *strtrim_left(register char *p, register char c) return p; } + -- 2.11.4.GIT