Code cleaning, SCTP support, NFLOG logic fix
cover Code cleaning, SCTP support, NFLOG logic fix
Hi,
This patchset is made of four parts.
First part is Pablo's work that I have completed. It cleans up the current key assignation by introducing a new set of functions:
* add ukey_* function for key assignation
Second part fixes a logic problem in NFLOG input plugin. System logging (for instance invalid conntrack message) are done on group 0 queue for all protocols. Thus a protocol dependant NFLOG plugin is stupid. Furthermore, the nfnetlink message contains the protocol information. This set of patch suppresses the addressfamily variable and modify NFLOG to only bind as system logging if group is 0:
* Modify usage of nflog_bind_pf function.
* Get rid of addressfamily variable in NFLOG input plugin
* Document group 0 usage and suppress address_family
Third part adds support for SCTP in ulogd2. It contains a basic packet parser and a support in all OUTPUT plugin:
* Add SCTP support to BASE plugin.
* SCTP support for PRINTPKT.
* Add SCTP support to MySQL and PGSQL output.
Last part is code cleaning. It fixes some memory leak fixes and cleaning of ulogd exit code.F or example, fini function were defined for each module but were never called:
* Treat nice function return.
* Fix stop function of NFCT plugin.
* Don't free pluginstance when leaving
* Fix minor memory leak in NFLOG plugin.
* Call pluginstance stop function when exiting
* Add SIGINT to list of terminal signal.
* Unload plugins when quitting.
* Introduce config_stop() function
* Free stacks when exiting.
* Fix memory leak in destructor_nfct().
* Add valgrind compilation option.
This patch is build upon Pierre's last patchset.
Patchset statistics:
doc/mysql-ulogd2.sql | 43 ++++- doc/pgsql-ulogd2.sql | 41 ++++- filter/raw2packet/ulogd_raw2packet_BASE.c | 270 +++++++++++++-------------- filter/raw2packet/ulogd_raw2packet_LOCAL.c | 7 +- filter/ulogd_filter_HWHDR.c | 76 ++++---- filter/ulogd_filter_IFINDEX.c | 30 ++-- filter/ulogd_filter_IP2BIN.c | 9 +- filter/ulogd_filter_IP2STR.c | 15 +- filter/ulogd_filter_MARK.c | 4 +- filter/ulogd_filter_PRINTFLOW.c | 3 +- filter/ulogd_filter_PRINTPKT.c | 3 +- filter/ulogd_filter_PWSNIFF.c | 27 ++-- include/ulogd/conffile.h | 3 + include/ulogd/printpkt.h | 2 + include/ulogd/ulogd.h | 68 +++++++- input/flow/ulogd_inpflow_NFCT.c | 171 +++++++----------- input/packet/ulogd_inppkt_NFLOG.c | 186 +++++++++----------- input/packet/ulogd_inppkt_ULOG.c | 46 ++---- output/pcap/ulogd_output_PCAP.c | 11 +- output/ulogd_output_NACCT.c | 34 ++-- src/conffile.c | 4 + src/hash.c | 6 +- src/ulogd.c | 76 ++++++++- ulogd.conf.in | 37 ++-- util/printflow.c | 52 +++--- util/printpkt.c | 163 +++++++++-------- 26 files changed, 768 insertions(+), 619 deletions(-)
BR,
--
Eric Leblond <[email protected]>
PATCH 1/18 add ukey_* function for key assignation
From: Pablo Neira Ayuso <[email protected]>
This patch cleans up the current key assignation by introducing a set of functions ukey_* to set the key value as Eric Leblond and we discussed during the latest Netfilter Workshop. This patch is based on an idea from Holger Eitzenberger.
--- filter/raw2packet/ulogd_raw2packet_BASE.c | 217 ++++++++++------------------ filter/raw2packet/ulogd_raw2packet_LOCAL.c | 7 +- filter/ulogd_filter_HWHDR.c | 76 +++++----- filter/ulogd_filter_IFINDEX.c | 30 +++-- filter/ulogd_filter_IP2BIN.c | 9 +- filter/ulogd_filter_IP2STR.c | 15 +- filter/ulogd_filter_MARK.c | 4 +- filter/ulogd_filter_PRINTFLOW.c | 3 +- filter/ulogd_filter_PRINTPKT.c | 3 +- filter/ulogd_filter_PWSNIFF.c | 27 ++-- include/ulogd/ulogd.h | 60 ++++++++- input/flow/ulogd_inpflow_NFCT.c | 159 +++++++-------------- input/packet/ulogd_inppkt_NFLOG.c | 101 +++++--------- input/packet/ulogd_inppkt_ULOG.c | 45 ++---- output/pcap/ulogd_output_PCAP.c | 11 +- output/ulogd_output_NACCT.c | 34 +++--- util/printflow.c | 52 ++++---- util/printpkt.c | 146 ++++++++++--------- 18 files changed, 448 insertions(+), 551 deletions(-)
filter/raw2packet/ulogd_raw2packet_BASE.c +77 -140
@@ -521,43 +521,25 @@ static int _interp_tcp(struct ulogd_pluginstance *pi, struct tcphdr *tcph,if (len <sizeof (struct tcphdr ))return ULOGD_IRET_OK ; - ret[KEY_TCP_SPORT ].u.value.ui16 =ntohs (tcph->source); - ret[KEY_TCP_SPORT ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_DPORT ].u.value.ui16 =ntohs (tcph->dest); - ret[KEY_TCP_DPORT ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_SEQ ].u.value.ui32 =ntohl (tcph->seq); - ret[KEY_TCP_SEQ ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_ACKSEQ ].u.value.ui32 =ntohl (tcph->ack_seq); - ret[KEY_TCP_ACKSEQ ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_OFFSET ].u.value.ui8 =ntohs (tcph->doff); - ret[KEY_TCP_OFFSET ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_RESERVED ].u.value.ui8 =ntohs (tcph->res1); - ret[KEY_TCP_RESERVED ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_WINDOW ].u.value.ui16 =ntohs (tcph->window); - ret[KEY_TCP_WINDOW ].flags |=ULOGD_RETF_VALID ; - - ret[KEY_TCP_URG ].u.value.b = tcph->urg; - ret[KEY_TCP_URG ].flags |=ULOGD_RETF_VALID ; -if (tcph->urg) { - ret[KEY_TCP_URGP ].u.value.ui16 =ntohs (tcph->urg_ptr); - ret[KEY_TCP_URGP ].flags |=ULOGD_RETF_VALID ; - } - ret[KEY_TCP_ACK ].u.value.b = tcph->ack; - ret[KEY_TCP_ACK ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_PSH ].u.value.b = tcph->psh; - ret[KEY_TCP_PSH ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_RST ].u.value.b = tcph->rst; - ret[KEY_TCP_RST ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_SYN ].u.value.b = tcph->syn; - ret[KEY_TCP_SYN ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_FIN ].u.value.b = tcph->fin; - ret[KEY_TCP_FIN ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_RES1 ].u.value.b = tcph->res1; - ret[KEY_TCP_RES1 ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_RES2 ].u.value.b = tcph->res2; - ret[KEY_TCP_RES2 ].flags |=ULOGD_RETF_VALID ; - ret[KEY_TCP_CSUM ].u.value.ui16 =ntohs (tcph->check); - ret[KEY_TCP_CSUM ].u.value.ui16 =ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_TCP_SPORT ],ntohs (tcph->source)); +okey_set_u16 (&ret[KEY_TCP_DPORT ],ntohs (tcph->dest)); +okey_set_u32 (&ret[KEY_TCP_SEQ ],ntohl (tcph->seq)); +okey_set_u32 (&ret[KEY_TCP_ACKSEQ ],ntohl (tcph->ack_seq)); +okey_set_u8 (&ret[KEY_TCP_OFFSET ],ntohs (tcph->doff)); +okey_set_u8 (&ret[KEY_TCP_RESERVED ],ntohs (tcph->res1)); +okey_set_u16 (&ret[KEY_TCP_WINDOW ],ntohs (tcph->window)); + +okey_set_b (&ret[KEY_TCP_URG ], tcph->urg); +if (tcph->urg) +okey_set_u16 (&ret[KEY_TCP_URGP ],ntohs (tcph->urg_ptr)); +okey_set_b (&ret[KEY_TCP_ACK ], tcph->ack); +okey_set_b (&ret[KEY_TCP_PSH ], tcph->psh); +okey_set_b (&ret[KEY_TCP_RST ], tcph->rst); +okey_set_b (&ret[KEY_TCP_SYN ], tcph->syn); +okey_set_b (&ret[KEY_TCP_FIN ], tcph->fin); +okey_set_b (&ret[KEY_TCP_RES1 ], tcph->res1); +okey_set_b (&ret[KEY_TCP_RES2 ], tcph->res2); +okey_set_u16 (&ret[KEY_TCP_CSUM ],ntohs (tcph->check));return ULOGD_IRET_OK ; }
@@ -575,14 +557,10 @@ static int _interp_udp(struct ulogd_pluginstance *pi, struct udphdr *udph,if (len <sizeof (struct udphdr ))return ULOGD_IRET_OK ; - ret[KEY_UDP_SPORT ].u.value.ui16 =ntohs (udph->source); - ret[KEY_UDP_SPORT ].flags |=ULOGD_RETF_VALID ; - ret[KEY_UDP_DPORT ].u.value.ui16 =ntohs (udph->dest); - ret[KEY_UDP_DPORT ].flags |=ULOGD_RETF_VALID ; - ret[KEY_UDP_LEN ].u.value.ui16 =ntohs (udph->len); - ret[KEY_UDP_LEN ].flags |=ULOGD_RETF_VALID ; - ret[KEY_UDP_CSUM ].u.value.ui16 =ntohs (udph->check); - ret[KEY_UDP_CSUM ].flags |=ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_UDP_SPORT ],ntohs (udph->source)); +okey_set_u16 (&ret[KEY_UDP_DPORT ],ntohs (udph->dest)); +okey_set_u16 (&ret[KEY_UDP_LEN ],ntohs (udph->len)); +okey_set_u16 (&ret[KEY_UDP_CSUM ],ntohs (udph->check));return ULOGD_IRET_OK ; }
@@ -599,33 +577,28 @@ static int _interp_icmp(struct ulogd_pluginstance *pi, struct icmphdr *icmph,if (len <sizeof (struct icmphdr ))return ULOGD_IRET_OK ; - ret[KEY_ICMP_TYPE ].u.value.ui8 = icmph->type; - ret[KEY_ICMP_TYPE ].flags |=ULOGD_RETF_VALID ; - ret[KEY_ICMP_CODE ].u.value.ui8 = icmph->code; - ret[KEY_ICMP_CODE ].flags |=ULOGD_RETF_VALID ; +okey_set_u8 (&ret[KEY_ICMP_TYPE ], icmph->type); +okey_set_u8 (&ret[KEY_ICMP_CODE ], icmph->code);switch (icmph->type) {case ICMP_ECHO :case ICMP_ECHOREPLY : - ret[KEY_ICMP_ECHOID ].u.value.ui16 =ntohs (icmph->un.echo.id); - ret[KEY_ICMP_ECHOID ].flags |=ULOGD_RETF_VALID ; - ret[KEY_ICMP_ECHOSEQ ].u.value.ui16 =ntohs (icmph->un.echo.sequence); - ret[KEY_ICMP_ECHOSEQ ].flags |=ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_ICMP_ECHOID ],ntohs (icmph->un.echo.id)); +okey_set_u16 (&ret[KEY_ICMP_ECHOSEQ ], +ntohs (icmph->un.echo.sequence));break ;case ICMP_REDIRECT :case ICMP_PARAMETERPROB : - ret[KEY_ICMP_GATEWAY ].u.value.ui32 =ntohl (icmph->un.gateway); - ret[KEY_ICMP_GATEWAY ].flags |=ULOGD_RETF_VALID ; +okey_set_u32 (&ret[KEY_ICMP_GATEWAY ],ntohl (icmph->un.gateway));break ;case ICMP_DEST_UNREACH :if (icmph->code ==ICMP_FRAG_NEEDED ) { - ret[KEY_ICMP_FRAGMTU ].u.value.ui16 =ntohs (icmph->un.frag.mtu); - ret[KEY_ICMP_FRAGMTU ].flags |=ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_ICMP_FRAGMTU ], +ntohs (icmph->un.frag.mtu)); }break ; } - ret[KEY_ICMP_CSUM ].u.value.ui16 = icmph->checksum; - ret[KEY_ICMP_CSUM ].flags |=ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_ICMP_CSUM ], icmph->checksum);return ULOGD_IRET_OK ; }
@@ -642,22 +615,18 @@ static int _interp_icmpv6(struct ulogd_pluginstance *pi, struct icmp6_hdr *icmphif (len <sizeof (struct icmp6_hdr ))return ULOGD_IRET_OK ; - ret[KEY_ICMPV6_TYPE ].u.value.ui8 = icmph->icmp6_type; - ret[KEY_ICMPV6_TYPE ].flags |=ULOGD_RETF_VALID ; - ret[KEY_ICMPV6_CODE ].u.value.ui8 = icmph->icmp6_code; - ret[KEY_ICMPV6_CODE ].flags |=ULOGD_RETF_VALID ; +okey_set_u8 (&ret[KEY_ICMPV6_TYPE ], icmph->icmp6_type); +okey_set_u8 (&ret[KEY_ICMPV6_CODE ], icmph->icmp6_code);switch (icmph->icmp6_type) {case ICMP6_ECHO_REQUEST :case ICMP6_ECHO_REPLY : - ret[KEY_ICMPV6_ECHOID ].u.value.ui16 =ntohs (icmph->icmp6_id); - ret[KEY_ICMPV6_ECHOID ].flags |=ULOGD_RETF_VALID ; - ret[KEY_ICMPV6_ECHOSEQ ].u.value.ui16 =ntohs (icmph->icmp6_seq); - ret[KEY_ICMPV6_ECHOSEQ ].flags |=ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_ICMPV6_ECHOID ],ntohs (icmph->icmp6_id)); +okey_set_u16 (&ret[KEY_ICMPV6_ECHOSEQ ], +ntohs (icmph->icmp6_seq));break ; } - ret[KEY_ICMPV6_CSUM ].u.value.ui16 = icmph->icmp6_cksum; - ret[KEY_ICMPV6_CSUM ].flags |=ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_ICMPV6_CSUM ], icmph->icmp6_cksum);return ULOGD_IRET_OK ; }
@@ -691,33 +660,23 @@ static int _interp_iphdr(struct ulogd_pluginstance *pi, u_int32_t len) {struct ulogd_key *ret = pi->output.keys;struct iphdr *iph = -GET_VALUE (pi->input.keys,INKEY_RAW_PCKT ).ptr; +ikey_get_ptr (&pi->input.keys[INKEY_RAW_PCKT ]);void *nexthdr = (u_int32_t *)iph + iph->ihl;if (len <sizeof (struct iphdr ) || len <= (u_int32_t)(iph->ihl *4 ))return ULOGD_IRET_OK ; len -= iph->ihl *4 ; - ret[KEY_IP_SADDR ].u.value.ui32 = iph->saddr; - ret[KEY_IP_SADDR ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_DADDR ].u.value.ui32 = iph->daddr; - ret[KEY_IP_DADDR ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_PROTOCOL ].u.value.ui8 = iph->protocol; - ret[KEY_IP_PROTOCOL ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_TOS ].u.value.ui8 = iph->tos; - ret[KEY_IP_TOS ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_TTL ].u.value.ui8 = iph->ttl; - ret[KEY_IP_TTL ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_TOTLEN ].u.value.ui16 =ntohs (iph->tot_len); - ret[KEY_IP_TOTLEN ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_IHL ].u.value.ui8 = iph->ihl; - ret[KEY_IP_IHL ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_CSUM ].u.value.ui16 =ntohs (iph->check); - ret[KEY_IP_CSUM ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_ID ].u.value.ui16 =ntohs (iph->id); - ret[KEY_IP_ID ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP_FRAGOFF ].u.value.ui16 =ntohs (iph->frag_off); - ret[KEY_IP_FRAGOFF ].flags |=ULOGD_RETF_VALID ; +okey_set_u32 (&ret[KEY_IP_SADDR ], iph->saddr); +okey_set_u32 (&ret[KEY_IP_DADDR ], iph->daddr); +okey_set_u8 (&ret[KEY_IP_PROTOCOL ], iph->protocol); +okey_set_u8 (&ret[KEY_IP_TOS ], iph->tos); +okey_set_u8 (&ret[KEY_IP_TTL ], iph->ttl); +okey_set_u16 (&ret[KEY_IP_TOTLEN ],ntohs (iph->tot_len)); +okey_set_u8 (&ret[KEY_IP_IHL ], iph->ihl); +okey_set_u16 (&ret[KEY_IP_CSUM ],ntohs (iph->check)); +okey_set_u16 (&ret[KEY_IP_ID ],ntohs (iph->id)); +okey_set_u16 (&ret[KEY_IP_FRAGOFF ],ntohs (iph->frag_off));switch (iph->protocol) {case IPPROTO_TCP :
@@ -760,8 +719,7 @@ static int ip6_ext_hdr(u_int8_t nexthdr)static int _interp_ipv6hdr (struct ulogd_pluginstance *pi,u_int32_t len) {struct ulogd_key *ret = pi->output.keys; -struct ip6_hdr *ipv6h = -GET_VALUE (pi->input.keys,INKEY_RAW_PCKT ).ptr; +struct ip6_hdr *ipv6h =ikey_get_ptr (&pi->input.keys[INKEY_RAW_PCKT ]);unsigned int ptr, hdrlen =0 ;u_int8_t curhdr;int fragment =0 ;
@@ -769,20 +727,14 @@ static int _interp_ipv6hdr(struct ulogd_pluginstance *pi, u_int32_t len)if (len <sizeof (struct ip6_hdr ))return ULOGD_IRET_OK ; -memcpy (ret[KEY_IP_SADDR ].u.value.ui128, &ipv6h->ip6_src, -sizeof (ipv6h->ip6_src)); - ret[KEY_IP_SADDR ].flags |=ULOGD_RETF_VALID ; -memcpy (ret[KEY_IP_DADDR ].u.value.ui128, &ipv6h->ip6_dst, -sizeof (ipv6h->ip6_dst)); - ret[KEY_IP_DADDR ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP6_PAYLOAD_LEN ].u.value.ui16 =ntohs (ipv6h->ip6_plen); - ret[KEY_IP6_PAYLOAD_LEN ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP6_PRIORITY ].u.value.ui8 =ntohl (ipv6h->ip6_flow &0x0ff00000 ) >>20 ; - ret[KEY_IP6_PRIORITY ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP6_FLOWLABEL ].u.value.ui32 =ntohl (ipv6h->ip6_flow &0x000fffff ); - ret[KEY_IP6_FLOWLABEL ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP6_HOPLIMIT ].u.value.ui8 = ipv6h->ip6_hlim; - ret[KEY_IP6_HOPLIMIT ].flags |=ULOGD_RETF_VALID ; +okey_set_u128 (&ret[KEY_IP_SADDR ], &ipv6h->ip6_src); +okey_set_u128 (&ret[KEY_IP_DADDR ], &ipv6h->ip6_dst); +okey_set_u16 (&ret[KEY_IP6_PAYLOAD_LEN ],ntohs (ipv6h->ip6_plen)); +okey_set_u8 (&ret[KEY_IP6_PRIORITY ], +ntohl (ipv6h->ip6_flow &0x0ff00000 ) >>20 ); +okey_set_u32 (&ret[KEY_IP6_FLOWLABEL ], +ntohl (ipv6h->ip6_flow &0x000fffff )); +okey_set_u8 (&ret[KEY_IP6_HOPLIMIT ], ipv6h->ip6_hlim); curhdr = ipv6h->ip6_nxt; ptr =sizeof (struct ip6_hdr );
@@ -803,10 +755,10 @@ static int _interp_ipv6hdr(struct ulogd_pluginstance *pi, u_int32_t len)return ULOGD_IRET_OK ; len -= hdrlen; - ret[KEY_IP6_FRAG_OFF ].u.value.ui16 =ntohs (fh->ip6f_offlg &IP6F_OFF_MASK ); - ret[KEY_IP6_FRAG_OFF ].flags |=ULOGD_RETF_VALID ; - ret[KEY_IP6_FRAG_ID ].u.value.ui32 =ntohl (fh->ip6f_ident); - ret[KEY_IP6_FRAG_ID ].flags |=ULOGD_RETF_VALID ; +okey_set_u16 (&ret[KEY_IP6_FRAG_OFF ], +ntohs (fh->ip6f_offlg &IP6F_OFF_MASK )); +okey_set_u32 (&ret[KEY_IP6_FRAG_ID ], +ntohl (fh->ip6f_ident));if (ntohs (fh->ip6f_offlg &IP6F_OFF_MASK )) fragment =1 ;
@@ -857,8 +809,7 @@ static int _interp_ipv6hdr(struct ulogd_pluginstance *pi, u_int32_t len) goto out; - ret[KEY_IP_PROTOCOL ].u.value.ui8 = curhdr; - ret[KEY_IP_PROTOCOL ].flags |=ULOGD_RETF_VALID ; +okey_set_u8 (&ret[KEY_IP_PROTOCOL ], curhdr);switch (curhdr) {case IPPROTO_TCP :
@@ -873,8 +824,7 @@ static int _interp_ipv6hdr(struct ulogd_pluginstance *pi, u_int32_t len) } out: - ret[KEY_IP6_NEXTHDR ].u.value.ui8 = curhdr; - ret[KEY_IP6_NEXTHDR ].flags |=ULOGD_RETF_VALID ; +okey_set_u8 (&ret[KEY_IP6_NEXTHDR ], curhdr);return ULOGD_IRET_OK ; }
@@ -885,31 +835,19 @@ static int _interp_arp(struct ulogd_pluginstance *pi, u_int32_t len) {struct ulogd_key *ret = pi->output.keys;const struct ether_arp *arph = -GET_VALUE (pi->input.keys,INKEY_RAW_PCKT ).ptr; +ikey_get_ptr (&pi->input.keys[INKEY_RAW_PCKT ]);if (len <sizeof (struct ether_arp ))return ULOGD_IRET_OK ; - ret[KEY_ARP_HTYPE ].u.value.ui16 =ntohs (arph->arp_hrd); -SET_VALID (ret[KEY_ARP_HTYPE ]); - ret[KEY_ARP_PTYPE ].u.value.ui16 =ntohs (arph->arp_pro); -SET_VALID (ret[KEY_ARP_PTYPE ]); - ret[KEY_ARP_OPCODE ].u.value.ui16 =ntohs (arph->arp_op); -SET_VALID (ret[KEY_ARP_OPCODE ]); - - ret[KEY_ARP_SHA ].u.value.ptr = &arph->arp_sha; -SET_VALID (ret[KEY_ARP_SHA ]); - -memcpy (&ret[KEY_ARP_SPA ].u.value.ui32, &arph->arp_spa, -sizeof (u_int32_t)); -SET_VALID (ret[KEY_ARP_SPA ]); - - ret[KEY_ARP_THA ].u.value.ptr = &arph->arp_tha; -SET_VALID (ret[KEY_ARP_THA ]); +okey_set_u16 (&ret[KEY_ARP_HTYPE ],ntohs (arph->arp_hrd)); +okey_set_u16 (&ret[KEY_ARP_PTYPE ],ntohs (arph->arp_pro)); +okey_set_u16 (&ret[KEY_ARP_OPCODE ],ntohs (arph->arp_op)); -memcpy (&ret[KEY_ARP_TPA ].u.value.ui32, &arph->arp_tpa, -sizeof (u_int32_t)); -SET_VALID (ret[KEY_ARP_TPA ]); +okey_set_ptr (&ret[KEY_ARP_SHA ], &arph->arp_sha); +okey_set_ptr (&ret[KEY_ARP_SPA ], &arph->arp_spa), +okey_set_ptr (&ret[KEY_ARP_THA ], &arph->arp_tha); +okey_set_ptr (&ret[KEY_ARP_TPA ], &arph->arp_tpa);return ULOGD_IRET_OK ; }
@@ -921,7 +859,7 @@ static int _interp_arp(struct ulogd_pluginstance *pi, u_int32_t len)static int _interp_bridge (struct ulogd_pluginstance *pi,u_int32_t len) {const u_int16_t proto = -GET_VALUE (pi->input.keys,INKEY_OOB_PROTOCOL ).ui16; +ikey_get_u16 (&pi->input.keys[INKEY_OOB_PROTOCOL ]);switch (proto) {case ETH_P_IP :
@@ -942,13 +880,12 @@ static int _interp_bridge(struct ulogd_pluginstance *pi, u_int32_t len)static int _interp_pkt (struct ulogd_pluginstance *pi) { -u_int32_t len =GET_VALUE (pi->input.keys,INKEY_RAW_PCKTLEN ).ui32; -u_int8_t family =GET_VALUE (pi->input.keys,INKEY_OOB_FAMILY ).ui8; +u_int32_t len =ikey_get_u32 (&pi->input.keys[INKEY_RAW_PCKTLEN ]); +u_int8_t family =ikey_get_u8 (&pi->input.keys[INKEY_OOB_FAMILY ]);struct ulogd_key *ret = pi->output.keys; - ret[KEY_OOB_PROTOCOL ].u.value.ui16 = -GET_VALUE (pi->input.keys,INKEY_OOB_PROTOCOL ).ui16; -SET_VALID (ret[KEY_OOB_PROTOCOL ]); +okey_set_u16 (&ret[KEY_OOB_PROTOCOL ], +ikey_get_u16 (&pi->input.keys[INKEY_OOB_PROTOCOL ]));switch (family) {case AF_INET :
filter/raw2packet/ulogd_raw2packet_LOCAL.c +2 -5
@@ -51,11 +51,8 @@ static ulog_iret_t *_interp_local(ulog_interpreter_t *ip,gettimeofday (&tv,NULL );/* put date */ - ret[0 ].value.ui32 = (unsigned long ) tv.tv_sec; - ret[0 ].flags |=ULOGD_RETF_VALID ; - - ret[1 ].value.ptr = hostname; - ret[1 ].flags |=ULOGD_RETF_VALID ; +okey_set_ui32 (&ret[0 ], (unsigned long ) tv.tv_sec); +okey_set_ptr (&ret[1 ], hostname);return ret; }
filter/ulogd_filter_HWHDR.c +40 -36
134 lines not on this page · raw message
filter/ulogd_filter_IFINDEX.c +19 -13
@@ -3,6 +3,7 @@* ulogd interpreter plugin for ifindex to ifname conversion * * (C) 2005 by Harald Welte <[email protected]> +* (C) 2008 by Pablo Neira Ayuso <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2
@@ -61,20 +62,25 @@ static int interp_ifindex(struct ulogd_pluginstance *pi) {struct ulogd_key *ret = pi->output.keys;struct ulogd_key *inp = pi->input.keys; +void *ptr; - ret[0 ].u.value.ptr =calloc (IFNAMSIZ ,sizeof (char )); -nlif_index2name (nlif_inst, inp[0 ].u.source->u.value.ui32, - ret[0 ].u.value.ptr); -if (((char *)ret[0 ].u.value.ptr)[0 ] =='*' ) - ((char *)(ret[0 ].u.value.ptr))[0 ] =0 ; - ret[0 ].flags |=ULOGD_RETF_VALID ; - - ret[1 ].u.value.ptr =calloc (IFNAMSIZ ,sizeof (char )); -nlif_index2name (nlif_inst, inp[1 ].u.source->u.value.ui32, - ret[1 ].u.value.ptr); -if (((char *)ret[1 ].u.value.ptr)[0 ] =='*' ) - ((char *)(ret[1 ].u.value.ptr))[0 ] =0 ; - ret[1 ].flags |=ULOGD_RETF_VALID ; + ptr =calloc (IFNAMSIZ ,sizeof (char )); +if (!ptr) +return ULOGD_IRET_ERR ; + +nlif_index2name (nlif_inst,ikey_get_u32 (&inp[0 ]), ptr); +if (((char *)ptr)[0 ] =='*' ) + ((char *)(ptr))[0 ] =0 ; +okey_set_ptr (&ret[0 ], ptr); + + ptr =calloc (IFNAMSIZ ,sizeof (char )); +if (!ptr) +return ULOGD_IRET_ERR ; + +nlif_index2name (nlif_inst,ikey_get_u32 (&inp[1 ]), ptr); +if (((char *)ptr)[0 ] =='*' ) + ((char *)(ptr))[0 ] =0 ; +okey_set_ptr (&ret[1 ], ptr);return ULOGD_IRET_OK ; }
filter/ulogd_filter_IP2BIN.c +4 -5
@@ -137,12 +137,12 @@ static char *ip2bin(struct ulogd_key* inp, int index, char family)switch (family) {case AF_INET6 : - addr = (struct in6_addr *)GET_VALUE (inp, index).ui128; + addr = (struct in6_addr *)ikey_get_u128 (&inp[index]);break ;case AF_INET :/* Convert IPv4 to IPv4 in IPv6 */ addr = &ip4_addr; -uint32_to_ipv6 (GET_VALUE (inp, index).ui32, addr); +uint32_to_ipv6 (ikey_get_u32 (&inp[index]), addr);break ;default :/* TODO handle error */
@@ -176,13 +176,12 @@ static int interp_ip2bin(struct ulogd_pluginstance *pi)struct ulogd_key *ret = pi->output.keys;struct ulogd_key *inp = pi->input.keys;int i; -int oob_family =GET_VALUE (inp,KEY_OOB_FAMILY ).ui8; +int oob_family =ikey_get_u8 (&inp[KEY_OOB_FAMILY ]);/* Iter on all addr fields */ for (i =START_KEY ; i <MAX_KEY ; i++) {if (pp_is_valid (inp, i)) { - ret[i-1 ].u.value.ptr =ip2bin (inp, i, oob_family); - ret[i-1 ].flags |=ULOGD_RETF_VALID ; +okey_set_ptr (&ret[i-1 ],ip2bin (inp, i, oob_family)); } }
filter/ulogd_filter_IP2STR.c +7 -8
@@ -145,7 +145,7 @@ static struct ulogd_key ip2str_keys[] = {static char *ip2str (struct ulogd_key *inp,int index) {char tmp[IPADDR_LENGTH ]; -char family =GET_VALUE (inp,KEY_OOB_FAMILY ).ui8; +char family =ikey_get_u8 (&inp[KEY_OOB_FAMILY ]);char convfamily = family;if (family ==AF_BRIDGE ) {
@@ -154,7 +154,7 @@ static char *ip2str(struct ulogd_key *inp, int index) "No protocol inside AF_BRIDGE packet\n");return NULL ; } -switch (GET_VALUE (inp,KEY_OOB_PROTOCOL ).ui16) { +switch (ikey_get_u16 (&inp[KEY_OOB_PROTOCOL ])) {case ETH_P_IPV6 : convfamily =AF_INET6 ;break ;
@@ -172,15 +172,15 @@ static char *ip2str(struct ulogd_key *inp, int index) }switch (convfamily) { +u_int32_t ip;case AF_INET6 :inet_ntop (AF_INET6 , -GET_VALUE (inp, index).ui128, +ikey_get_u128 (&inp[index]), tmp,sizeof (tmp));break ;case AF_INET : -inet_ntop (AF_INET , - &GET_VALUE (inp, index).ui32, - tmp,sizeof (tmp)); + ip =ikey_get_u32 (&inp[index]); +inet_ntop (AF_INET , &ip, tmp,sizeof (tmp));break ;default :/* TODO error handling */
@@ -199,8 +199,7 @@ static int interp_ip2str(struct ulogd_pluginstance *pi)/* Iter on all addr fields */ for (i =START_KEY ; i <=MAX_KEY ; i++) {if (pp_is_valid (inp, i)) { - ret[i-START_KEY ].u.value.ptr =ip2str (inp, i); - ret[i-START_KEY ].flags |=ULOGD_RETF_VALID ; +okey_set_ptr (&ret[i-START_KEY ],ip2str (inp, i)); } }
filter/ulogd_filter_MARK.c +2 -2
@@ -72,14 +72,14 @@ static int interp_mark(struct ulogd_pluginstance *pi) {struct ulogd_key *inp = pi->input.keys;if (pp_is_valid (inp,KEY_CT_MARK )) { -if ((GET_VALUE (inp,KEY_CT_MARK ).ui32 & +if ((ikey_get_u32 (&inp[KEY_CT_MARK ]) & pi->config_kset->ces[MARK_MASK ].u.value) != (u_int32_t ) pi->config_kset->ces[MARK_MARK ].u.value ) {return ULOGD_IRET_STOP ; } }else if (pp_is_valid (inp,KEY_OOB_MARK )) { -if ((GET_VALUE (inp,KEY_OOB_MARK ).ui32 & +if ((ikey_get_u32 (&inp[KEY_OOB_MARK ]) & pi->config_kset->ces[MARK_MASK ].u.value) != (u_int32_t ) pi->config_kset->ces[MARK_MARK ].u.value ) {
filter/ulogd_filter_PRINTFLOW.c +1 -2
@@ -37,8 +37,7 @@ static int printflow_interp(struct ulogd_pluginstance *upi)static char buf[4096 ];printflow_print (inp, buf); - ret[0 ].u.value.ptr = buf; - ret[0 ].flags |=ULOGD_RETF_VALID ; +okey_set_ptr (&ret[0 ], buf);return ULOGD_IRET_OK ; }
filter/ulogd_filter_PRINTPKT.c +1 -2
@@ -37,8 +37,7 @@ static int printpkt_interp(struct ulogd_pluginstance *upi)static char buf[4096 ];printpkt_print (inp, buf); - ret[0 ].u.value.ptr = buf; - ret[0 ].flags |=ULOGD_RETF_VALID ; +okey_set_ptr (&ret[0 ], buf);return ULOGD_IRET_OK ; }
filter/ulogd_filter_PWSNIFF.c +12 -15
@@ -116,25 +116,22 @@ static int interp_pwsniff(struct ulogd_pluginstance *pi) }if (len) { - ret[0 ].u.value.ptr = (char *)malloc (len+1 ); - ret[0 ].flags |=ULOGD_RETF_VALID ; -if (!ret[0 ].u.value.ptr) { -ulogd_log (ULOGD_ERROR ,"OOM (size=%u)\n" , len); +char *ptr; + ptr = (char *)malloc (len+1 ); +if (!ptr)return ULOGD_IRET_ERR ; - } -strncpy ((char *) ret[0 ].u.value.ptr, (char *)begp, len); - *((char *)ret[0 ].u.value.ptr + len) ='\0' ; +strncpy (ptr, (char *)begp, len); + ptr[len] ='\0' ; +okey_set_ptr (&ret[0 ], ptr); }if (pw_len) { - ret[1 ].u.value.ptr = (char *)malloc (pw_len+1 ); - ret[1 ].flags |=ULOGD_RETF_VALID ; -if (!ret[1 ].u.value.ptr){ -ulogd_log (ULOGD_ERROR ,"OOM (size=%u)\n" , pw_len); +char *ptr; + ptr = (char *)malloc (pw_len+1 ); +if (!ptr)return ULOGD_IRET_ERR ; - } -strncpy ((char *)ret[1 ].u.value.ptr, (char *)pw_begp, pw_len); - *((char *)ret[1 ].u.value.ptr + pw_len) ='\0' ; - +strncpy (ptr, (char *)pw_begp, pw_len); + ptr[pw_len] ='\0' ; +okey_set_ptr (&ret[1 ], ptr); }return ULOGD_IRET_OK ; }
include/ulogd/ulogd.h +59 -1
78 lines not on this page · raw message
input/flow/ulogd_inpflow_NFCT.c +53 -106
197 lines not on this page · raw message
input/packet/ulogd_inppkt_NFLOG.c +35 -66
135 lines not on this page · raw message
input/packet/ulogd_inppkt_ULOG.c +15 -30
69 lines not on this page · raw message
output/pcap/ulogd_output_PCAP.c +5 -6
@@ -126,7 +126,6 @@ static struct ulogd_key pcap_keys[INTR_IDS] = { { .name = "oob.time.usec" }, }; -#define GET_VALUE (res, x) (res[x].u.source->u.value)#define GET_FLAGS (res, x) (res[x].u.source->flags)static int interp_pcap (struct ulogd_pluginstance *upi)
@@ -135,13 +134,13 @@ static int interp_pcap(struct ulogd_pluginstance *upi)struct ulogd_key *res = upi->input.keys;struct pcap_sf_pkthdr pchdr; - pchdr.caplen =GET_VALUE (res,2 ).ui32; - pchdr.len =GET_VALUE (res,2 ).ui32; + pchdr.caplen =ikey_get_u32 (&res[2 ]); + pchdr.len =ikey_get_u32 (&res[2 ]);if (GET_FLAGS (res,3 ) &ULOGD_RETF_VALID &&GET_FLAGS (res,4 ) &ULOGD_RETF_VALID ) { - pchdr.ts.tv_sec =GET_VALUE (res,3 ).ui32; - pchdr.ts.tv_usec =GET_VALUE (res,4 ).ui32; + pchdr.ts.tv_sec =ikey_get_u32 (&res[3 ]); + pchdr.ts.tv_usec =ikey_get_u32 (&res[4 ]); }else {/* use current system time */ struct timeval tv;
@@ -156,7 +155,7 @@ static int interp_pcap(struct ulogd_pluginstance *upi) strerror(errno));return ULOGD_IRET_ERR ; } -if (fwrite (GET_VALUE (res,0 ).ptr, pchdr.caplen,1 , pi->of) !=1 ) { +if (fwrite (ikey_get_ptr (&res[0 ]), pchdr.caplen,1 , pi->of) !=1 ) {ulogd_log (ULOGD_ERROR ,"Error during write: %s\n" ,strerror (errno));return ULOGD_IRET_ERR ;
output/ulogd_output_NACCT.c +17 -17
@@ -125,28 +125,28 @@ nacct_interp(struct ulogd_pluginstance *pi)/* try to be as close to nacct as possible. Instead of nacct's 'timestamp' value use 'flow.end.sec' */ -if (GET_VALUE (inp,KEY_IP_PROTO ).ui8 ==IPPROTO_ICMP ) { +if (ikey_get_u8 (&inp[KEY_IP_PROTO ]) ==IPPROTO_ICMP ) {snprintf (buf,sizeof (buf),"%u\t%u\t%s\t%u\t%s\t%u\t%u\t%u" , -GET_VALUE (inp,KEY_FLOW_END ).ui32, -GET_VALUE (inp,KEY_IP_PROTO ).ui8, - (char *)GET_VALUE (inp,KEY_IP_SADDR ).ptr, -GET_VALUE (inp,KEY_ICMP_TYPE ).ui8, - (char *)GET_VALUE (inp,KEY_IP_DADDR ).ptr, -GET_VALUE (inp,KEY_ICMP_CODE ).ui8, -GET_VALUE (inp,KEY_RAW_PKTCNT ).ui32, -GET_VALUE (inp,KEY_RAW_PKTLEN ).ui32); +ikey_get_u32 (&inp[KEY_FLOW_END ]), +ikey_get_u8 (&inp[KEY_IP_PROTO ]), + (char *)ikey_get_ptr (&inp[KEY_IP_SADDR ]), +ikey_get_u8 (&inp[KEY_ICMP_TYPE ]), + (char *)ikey_get_ptr (&inp[KEY_IP_DADDR ]), +ikey_get_u8 (&inp[KEY_ICMP_CODE ]), +ikey_get_u32 (&inp[KEY_RAW_PKTCNT ]), +ikey_get_u32 (&inp[KEY_RAW_PKTLEN ])); }else {snprintf (buf,sizeof (buf),"%u\t%u\t%s\t%u\t%s\t%u\t%u\t%u" , -GET_VALUE (inp,KEY_FLOW_END ).ui32, -GET_VALUE (inp,KEY_IP_PROTO ).ui8, - (char *)GET_VALUE (inp,KEY_IP_SADDR ).ptr, -GET_VALUE (inp,KEY_L4_SPORT ).ui16, - (char *)GET_VALUE (inp,KEY_IP_DADDR ).ptr, -GET_VALUE (inp,KEY_L4_DPORT ).ui16, -GET_VALUE (inp,KEY_RAW_PKTCNT ).ui32, -GET_VALUE (inp,KEY_RAW_PKTLEN ).ui32); +ikey_get_u32 (&inp[KEY_FLOW_END ]), +ikey_get_u8 (&inp[KEY_IP_PROTO ]), + (char *)ikey_get_ptr (&inp[KEY_IP_SADDR ]), +ikey_get_u16 (&inp[KEY_L4_SPORT ]), + (char *)ikey_get_ptr (&inp[KEY_IP_DADDR ]), +ikey_get_u16 (&inp[KEY_L4_DPORT ]), +ikey_get_u32 (&inp[KEY_RAW_PKTCNT ]), +ikey_get_u32 (&inp[KEY_RAW_PKTLEN ])); }fprintf (priv->of,"%s\n" , buf);
util/printflow.c +26 -26
132 lines not on this page · raw message
util/printpkt.c +74 -72
342 lines not on this page · raw message
Signature · 1 line
1.5.6.3
PATCH 2/18 Modify usage of nflog_bind_pf function.
In reply to Eric LeblondThe nflog_bind_pf function was called for each NFLOG instance. This patch modifies the behaviour to have it call if and only if the nfgroup is set to 0. As the kernel uses only the 0 group to output subsystem messages, this change clarify the situation.
--- input/packet/ulogd_inppkt_NFLOG.c | 52 ++++++++++++++++++++++-------------- 1 files changed, 32 insertions(+), 20 deletions(-)
input/packet/ulogd_inppkt_NFLOG.c +32 -20
@@ -463,6 +463,33 @@ static int configure(struct ulogd_pluginstance *upi,return 0 ; } +static int become_system_logging (struct ulogd_pluginstance *upi) +{ +struct nflog_input *ui = (struct nflog_input *) upi->private; + +if (unbind_ce (upi->config_kset).u.value >0 ) { +ulogd_log (ULOGD_NOTICE ,"forcing unbind of existing log " +"handler for protocol %d\n" , +af_ce (upi->config_kset).u.value); +if (nflog_unbind_pf (ui->nful_h, +af_ce (upi->config_kset).u.value) <0 ) { +ulogd_log (ULOGD_ERROR ,"unable to force-unbind " +"existing log handler for protocol %d\n" , +af_ce (upi->config_kset).u.value); +return -1 ; + } + } + +ulogd_log (ULOGD_DEBUG ,"binding to protocol family %d\n" , +af_ce (upi->config_kset).u.value); +if (nflog_bind_pf (ui->nful_h,af_ce (upi->config_kset).u.value) <0 ) { +ulogd_log (ULOGD_ERROR ,"unable to bind to protocol family %d\n" , +af_ce (upi->config_kset).u.value); +return -1 ; + } +return 0 ; +} +static int start (struct ulogd_pluginstance *upi) {struct nflog_input *ui = (struct nflog_input *) upi->private;
@@ -477,25 +504,10 @@ static int start(struct ulogd_pluginstance *upi)if (!ui->nful_h) goto out_handle; -if (unbind_ce (upi->config_kset).u.value >0 ) { -ulogd_log (ULOGD_NOTICE ,"forcing unbind of existing log " -"handler for protocol %d\n" , -af_ce (upi->config_kset).u.value); -if (nflog_unbind_pf (ui->nful_h, -af_ce (upi->config_kset).u.value) <0 ) { -ulogd_log (ULOGD_ERROR ,"unable to force-unbind " -"existing log handler for protocol %d\n" , -af_ce (upi->config_kset).u.value); +/* This is the system logging (conntrack, ...) facility */ +if (group_ce (upi->config_kset).u.value ==0 ) { +if (become_system_logging (upi) ==-1 ) goto out_handle; - } - } - -ulogd_log (ULOGD_DEBUG ,"binding to protocol family %d\n" , -af_ce (upi->config_kset).u.value); -if (nflog_bind_pf (ui->nful_h,af_ce (upi->config_kset).u.value) <0 ) { -ulogd_log (ULOGD_ERROR ,"unable to bind to protocol family %d\n" , -af_ce (upi->config_kset).u.value); - goto out_bind_pf; } ulogd_log(ULOGD_DEBUG, "binding to log group %d\n",
@@ -542,8 +554,8 @@ static int start(struct ulogd_pluginstance *upi) out_bind:nflog_close (ui->nful_h); -out_bind_pf: -nflog_unbind_pf (ui->nful_h,af_ce (upi->config_kset).u.value); +if (group_ce (upi->config_kset).u.value ==0 ) +nflog_unbind_pf (ui->nful_h,af_ce (upi->config_kset).u.value); out_handle:free (ui->nfulog_buf); out_buf:
Signature · 1 line
1.5.6.3
PATCH 3/18 Get rid of addressfamily variable in NFLOG input plugin
In reply to Eric LeblondThe addressfamily configuration variable for NFLOG is used as param for nflog_bind_pf. This function is used to claim the fetching of kernel message sent via nf_log_packet() function.
As all kernel messages are sent to the group 0, it is useless to call nflog_bind_pf when nflog group of the input plugin is not 0. Furthermore, as only one plugin can be bound to nflog group 0, it is mandatory to call nflog_bind_pf for all pf family when the group is 0.
To sum up, this patch suppress the adressfamily parameter (which simplify the configuration file) and call nflog_bind_pf for all pf family when the nflog group of the instance is 0.
--- input/packet/ulogd_inppkt_NFLOG.c | 59 ++++++++++++++++++------------------- 1 files changed, 29 insertions(+), 30 deletions(-)
input/packet/ulogd_inppkt_NFLOG.c +29 -30
@@ -46,12 +46,6 @@ static struct config_keyset libulog_kset = { .u.value = NFLOG_GROUP_DEFAULT, }, { - .key = "addressfamily", - .type = CONFIG_TYPE_INT, - .options = CONFIG_OPT_NONE, - .u.value = AF_INET, - }, - { .key = "unbind", .type = CONFIG_TYPE_INT, .options = CONFIG_OPT_NONE,
@@ -92,13 +86,12 @@ static struct config_keyset libulog_kset = {#define bufsiz_ce (x) (x->ces[0])#define group_ce (x) (x->ces[1]) -#define af_ce (x) (x->ces[2]) -#define unbind_ce (x) (x->ces[3]) -#define seq_ce (x) (x->ces[4]) -#define seq_global_ce (x) (x->ces[5]) -#define label_ce (x) (x->ces[6]) -#define nlsockbufsize_ce (x) (x->ces[7]) -#define nlsockbufmaxsize_ce (x) (x->ces[8]) +#define unbind_ce (x) (x->ces[2]) +#define seq_ce (x) (x->ces[3]) +#define seq_global_ce (x) (x->ces[4]) +#define label_ce (x) (x->ces[5]) +#define nlsockbufsize_ce (x) (x->ces[6]) +#define nlsockbufmaxsize_ce (x) (x->ces[7])enum nflog_keys {NFLOG_KEY_RAW_MAC =0 ,
@@ -293,7 +286,8 @@ static struct ulogd_key output_keys[] = { };static inline int -interp_packet (struct ulogd_pluginstance *upi,struct nflog_data *ldata) +interp_packet (struct ulogd_pluginstance *upi,u_int8_t pf_family, +struct nflog_data *ldata) {struct ulogd_key *ret = upi->output.keys;
@@ -311,7 +305,7 @@ interp_packet(struct ulogd_pluginstance *upi, struct nflog_data *ldata)u_int32_t gid;okey_set_u8 (&ret[NFLOG_KEY_OOB_FAMILY ], -af_ce (upi->config_kset).u.value); + pf_family);okey_set_u8 (&ret[NFLOG_KEY_RAW_LABEL ],label_ce (upi->config_kset).u.value);
@@ -446,11 +440,11 @@ static int msg_cb(struct nflog_g_handle *gh, struct nfgenmsg *nfmsg,/* since we support the re-use of one instance in several * different stacks, we duplicate the message to let them know */ llist_for_each_entry (npi, &upi->plist, plist) { - ret =interp_packet (npi, nfa); + ret =interp_packet (npi, nfmsg->nfgen_family, nfa);if (ret !=0 )return ret; } -return interp_packet (upi, nfa); +return interp_packet (upi, nfmsg->nfgen_family, nfa); } static int configure(struct ulogd_pluginstance *upi,
@@ -463,28 +457,26 @@ static int configure(struct ulogd_pluginstance *upi,return 0 ; } -static int become_system_logging (struct ulogd_pluginstance *upi) +static int become_system_logging (struct ulogd_pluginstance *upi,u_int8_t pf) {struct nflog_input *ui = (struct nflog_input *) upi->private;if (unbind_ce (upi->config_kset).u.value >0 ) {ulogd_log (ULOGD_NOTICE ,"forcing unbind of existing log " "handler for protocol %d\n" , -af_ce (upi->config_kset).u.value); -if (nflog_unbind_pf (ui->nful_h, -af_ce (upi->config_kset).u.value) <0 ) { + pf); +if (nflog_unbind_pf (ui->nful_h, pf) <0 ) {ulogd_log (ULOGD_ERROR ,"unable to force-unbind " "existing log handler for protocol %d\n" , -af_ce (upi->config_kset).u.value); + pf);return -1 ; } } -ulogd_log (ULOGD_DEBUG ,"binding to protocol family %d\n" , -af_ce (upi->config_kset).u.value); -if (nflog_bind_pf (ui->nful_h,af_ce (upi->config_kset).u.value) <0 ) { -ulogd_log (ULOGD_ERROR ,"unable to bind to protocol family %d\n" , -af_ce (upi->config_kset).u.value); +ulogd_log (ULOGD_DEBUG ,"binding to protocol family %d\n" , pf); +if (nflog_bind_pf (ui->nful_h, pf) <0 ) { +ulogd_log (ULOGD_ERROR ,"unable to bind to" +" protocol family %d\n" , pf);return -1 ; }return 0 ;
@@ -506,7 +498,11 @@ static int start(struct ulogd_pluginstance *upi)/* This is the system logging (conntrack, ...) facility */ if (group_ce (upi->config_kset).u.value ==0 ) { -if (become_system_logging (upi) ==-1 ) +if (become_system_logging (upi,AF_INET ) ==-1 ) + goto out_handle; +if (become_system_logging (upi,AF_INET6 ) ==-1 ) + goto out_handle; +if (become_system_logging (upi,AF_BRIDGE ) ==-1 ) goto out_handle; }
@@ -554,8 +550,11 @@ static int start(struct ulogd_pluginstance *upi) out_bind:nflog_close (ui->nful_h); -if (group_ce (upi->config_kset).u.value ==0 ) -nflog_unbind_pf (ui->nful_h,af_ce (upi->config_kset).u.value); +if (group_ce (upi->config_kset).u.value ==0 ) { +nflog_unbind_pf (ui->nful_h,AF_INET ); +nflog_unbind_pf (ui->nful_h,AF_INET6 ); +nflog_unbind_pf (ui->nful_h,AF_BRIDGE ); + } out_handle:free (ui->nfulog_buf); out_buf:
Signature · 1 line
1.5.6.3
PATCH 4/18 Document group 0 usage and suppress address_family
In reply to Eric LeblondDocument the fact that group 0 is used by system logging and update stack and plugin definition to match the suppression of the address_family variable.
--- ulogd.conf.in | 37 ++++++++++++++++++++----------------- 1 files changed, 20 insertions(+), 17 deletions(-)
ulogd.conf.in +20 -17
@@ -45,20 +45,17 @@ plugin="@libdir@/ulogd/ulogd_output_SYSLOG.so" #plugin="@libdir@/ulogd/ulogd_output_DBI.so" plugin="@libdir@/ulogd/ulogd_raw2packet_BASE.so" -# this is a stack for IPv4 packet-based logging via LOGEMU +# this is a stack for logging packet send by system via LOGEMU #stack=log1:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU -# this is a stack for IPv6 packet-based logging via LOGEMU +# this is a stack for packet-based logging via LOGEMU #stack=log2:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU -# this is a stack for ebtables packet-based logging via LOGEMU -#stack=log3:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU - # this is a stack for ULOG packet-based logging via LOGEMU #stack=ulog1:ULOG,base1:BASE,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU -# this is a stack for IPv4 packet-based logging via LOGEMU with filtering on MARK -#stack=log1:NFLOG,mark1:MARK,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU +# this is a stack for packet-based logging via LOGEMU with filtering on MARK +#stack=log2:NFLOG,mark1:MARK,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU # this is a stack for flow-based logging via LOGEMU #stack=ct1:NFCT,ip2str1:IP2STR,print1:PRINTFLOW,emu1:LOGEMU
@@ -67,15 +64,15 @@ plugin="@libdir@/ulogd/ulogd_raw2packet_BASE.so" #stack=ct1:NFCT,op1:OPRINT # this is a stack for NFLOG packet-based logging to PCAP -#stack=log1:NFLOG,base1:BASE,pcap1:PCAP +#stack=log2:NFLOG,base1:BASE,pcap1:PCAP # this is a stack for logging packet to MySQL -#stack=log1:NFLOG,base1:BASE,ifi1:IFINDEX,ip2bin1:IP2BIN,mac2str1:MAC2STR,mysql1:MYSQL +#stack=log2:NFLOG,base1:BASE,ifi1:IFINDEX,ip2bin1:IP2BIN,mac2str1:MAC2STR,mysql1:MYSQL -# this is a stack for logging IPv6 packet to PGsql after a collect via NFLOG +# this is a stack for logging packet to PGsql after a collect via NFLOG #stack=log2:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,mac2str1:MAC2STR,pgsql1:PGSQL -# this is a stack for logging ebtables packets to syslog after a collect via NFLOG +# this is a stack for logging packets to syslog after a collect via NFLOG #stack=log3:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,sys1:SYSLOG # this is a stack for flow-based logging to MySQL
@@ -100,23 +97,29 @@ plugin="@libdir@/ulogd/ulogd_raw2packet_BASE.so" #netlink_socket_buffer_maxsize=1085440 hash_enable=0 -# IPv4 logging through NFLOG +# Logging of system packet through NFLOG [log1] # netlink multicast group (the same as the iptables --nflog-group param) +# Group O is used by the kernel to log connection tracking invalid message group=0 #netlink_socket_buffer_size=217088 #netlink_socket_buffer_maxsize=1085440 -# IPv6 logging through NFLOG +# packet logging through NFLOG for group 1 [log2] +# netlink multicast group (the same as the iptables --nflog-group param) group=1 # Group has to be different from the one use in log1 -addressfamily=10 # 10 is value of AF_INET6 -numeric_label=1 # you can label the log info based on the packet verdict +#netlink_socket_buffer_size=217088 +#netlink_socket_buffer_maxsize=1085440 -# ebtables logging through NFLOG +# packet logging through NFLOG for group 2, numeric_label is +# set to 1 [log3] +# netlink multicast group (the same as the iptables --nflog-group param) group=2 # Group has to be different from the one use in log1/log2 -addressfamily=7 # 7 is value of AF_BRIDGE +numeric_label=1 # you can label the log info based on the packet verdict +#netlink_socket_buffer_size=217088 +#netlink_socket_buffer_maxsize=1085440 [ulog1] # netlink multicast group (the same as the iptables --ulog-nlgroup param)
Signature · 1 line
1.5.6.3
PATCH 5/18 Add SCTP support to BASE plugin.
In reply to Eric LeblondTHis patch adds basic support for SCTP in the BASE plugin.
--- filter/raw2packet/ulogd_raw2packet_BASE.c | 53 +++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-)
filter/raw2packet/ulogd_raw2packet_BASE.c +53 -0
@@ -113,6 +113,10 @@ enum output_keys {KEY_ARP_SPA ,KEY_ARP_THA ,KEY_ARP_TPA , +KEY_SCTP_SPORT , +KEY_SCTP_DPORT , + KEY_SCTP_CSUM, + }; static struct ulogd_key iphdr_rets[] = {
@@ -507,6 +511,21 @@ static struct ulogd_key iphdr_rets[] = { .flags = ULOGD_RETF_NONE, .name = "arp.daddr", }, + [KEY_SCTP_SPORT] = { + .type = ULOGD_RET_UINT16, + .flags = ULOGD_RETF_NONE, + .name = "sctp.sport", + }, + [KEY_SCTP_DPORT] = { + .type = ULOGD_RET_UINT16, + .flags = ULOGD_RETF_NONE, + .name = "sctp.dport", + }, + [KEY_SCTP_CSUM] = { + .type = ULOGD_RET_UINT32, + .flags = ULOGD_RETF_NONE, + .name = "sctp.csum", + }, };/***********************************************************************
@@ -566,6 +585,37 @@ static int _interp_udp(struct ulogd_pluginstance *pi, struct udphdr *udph, }/*********************************************************************** +* SCTP HEADER +***********************************************************************/ + +/* Section 3.1. SCTP Common Header Format */ +typedef struct sctphdr { +__be16 source; +__be16 dest; +__be32 vtag; +__be32 checksum; +} __attribute__((packed))sctp_sctphdr_t ; + +static int _interp_sctp (struct ulogd_pluginstance *pi,struct sctphdr *sctph, +u_int32_t len) + +{ +struct ulogd_key *ret = pi->output.keys; + +if (len <sizeof (struct sctphdr )) +return ULOGD_IRET_OK ; + + ret[KEY_SCTP_SPORT ].u.value.ui16 =ntohs (sctph->source); + ret[KEY_SCTP_SPORT ].flags |=ULOGD_RETF_VALID ; + ret[KEY_SCTP_DPORT ].u.value.ui16 =ntohs (sctph->dest); + ret[KEY_SCTP_DPORT ].flags |=ULOGD_RETF_VALID ; + ret[KEY_SCTP_CSUM ].u.value.ui32 =ntohl (sctph->checksum); + ret[KEY_SCTP_CSUM ].flags |=ULOGD_RETF_VALID ; + +return ULOGD_IRET_OK ; +} + +/*********************************************************************** * ICMP HEADER ***********************************************************************/
@@ -688,6 +738,9 @@ static int _interp_iphdr(struct ulogd_pluginstance *pi, u_int32_t len)case IPPROTO_ICMP :_interp_icmp (pi, nexthdr, len);break ; +case IPPROTO_SCTP : +_interp_sctp (pi, nexthdr, len); +break ;case IPPROTO_AH :case IPPROTO_ESP :_interp_ahesp (pi, nexthdr, len);
Signature · 1 line
1.5.6.3
PATCH 6/18 SCTP support for PRINTPKT.
In reply to Eric LeblondThis patch modifies PRINTPKT plugin to add SCTP support.
--- include/ulogd/printpkt.h | 2 ++ util/printpkt.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletions(-)
include/ulogd/printpkt.h +2 -0
@@ -61,6 +61,8 @@ enum pkt_keys {KEY_ARP_SPA ,KEY_ARP_THA ,KEY_ARP_TPA , +KEY_SCTP_SPORT , +KEY_SCTP_DPORT , __PRINTPKT_KEYS };#define PRINTPKT_KEYS (__PRINTPKT_KEYS)
util/printpkt.c +16 -1
@@ -102,7 +102,8 @@ struct ulogd_key printpkt_keys[] = { [KEY_ARP_SPA] = { .name = "arp.saddr.str", }, [KEY_ARP_THA] = { .name = "arp.dhwaddr", }, [KEY_ARP_TPA] = { .name = "arp.daddr.str", }, - + [KEY_SCTP_SPORT] = { .name = "sctp.sport", }, + [KEY_SCTP_DPORT] = { .name = "sctp.dport", }, };static int printpkt_proto (struct ulogd_key *res,char *buf,int protocol)
@@ -167,6 +168,18 @@ static int printpkt_proto(struct ulogd_key *res, char *buf, int protocol)ikey_get_u16 (&res[KEY_UDP_DPORT ]), ikey_get_u16(&res[KEY_UDP_LEN]));break ; +case IPPROTO_SCTP : + buf_cur +=sprintf (buf_cur,"PROTO=SCTP " ); + +if (!pp_is_valid (res,KEY_SCTP_SPORT )) { + buf_cur +=sprintf (buf_cur,"INCOMPLETE" ); +break ; + } + + buf_cur +=sprintf (buf_cur,"SPT=%u DPT=%u " , +ikey_get_u16 (&res[KEY_SCTP_SPORT ]), +ikey_get_u16 (&res[KEY_SCTP_DPORT ])); +break ;case IPPROTO_ESP :case IPPROTO_AH : buf_cur += sprintf(buf_cur, "PROTO=%s ",
@@ -223,6 +236,7 @@ static int printpkt_ipv4(struct ulogd_key *res, char *buf)switch (ikey_get_u8 (&res[KEY_IP_PROTOCOL ])) {case IPPROTO_TCP :case IPPROTO_UDP : +case IPPROTO_SCTP :case IPPROTO_ESP :case IPPROTO_AH : buf_cur += printpkt_proto(res, buf_cur,
@@ -311,6 +325,7 @@ static int printpkt_ipv6(struct ulogd_key *res, char *buf)switch (ikey_get_u8 (&res[KEY_IP6_NEXTHDR ])) {case IPPROTO_TCP :case IPPROTO_UDP : +case IPPROTO_SCTP :case IPPROTO_ESP :case IPPROTO_AH : buf_cur += printpkt_proto(res, buf_cur,
Signature · 1 line
1.5.6.3
PATCH 7/18 Add SCTP support to MySQL and PGSQL output.
In reply to Eric LeblondThis patch adds support for SCTP in the MySQL and PGSQL output plugins. It adds a dedicated SCTP table and modifies the insert_packet_full procedure.
--- doc/mysql-ulogd2.sql | 43 ++++++++++++++++++++++++++++++++++++++++--- doc/pgsql-ulogd2.sql | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 5 deletions(-)
doc/mysql-ulogd2.sql +40 -3
@@ -31,6 +31,7 @@ DROP TABLE IF EXISTS `mac`; DROP TABLE IF EXISTS `hwhdr`; DROP TABLE IF EXISTS `tcp`; DROP TABLE IF EXISTS `udp`; +DROP TABLE IF EXISTS `sctp`; DROP TABLE IF EXISTS `icmp`; DROP TABLE IF EXISTS `icmpv6`; DROP TABLE IF EXISTS `nufw`;
@@ -128,6 +129,19 @@ ALTER TABLE udp ADD KEY `index_udp_id` (`_udp_id`); ALTER TABLE udp ADD KEY `udp_sport` (`udp_sport`); ALTER TABLE udp ADD KEY `udp_dport` (`udp_dport`); +CREATE TABLE `sctp` ( + `_sctp_id` bigint unsigned NOT NULL, + `sctp_sport` int(5) unsigned default NULL, + `sctp_dport` int(5) unsigned default NULL, + `sctp_csum` int(5) unsigned default NULL +) ENGINE=INNODB; + +ALTER TABLE sctp ADD UNIQUE KEY `_sctp_id` (`_sctp_id`); +ALTER TABLE sctp ADD KEY `index_sctp_id` (`_sctp_id`); +ALTER TABLE sctp ADD KEY `sctp_sport` (`sctp_sport`); +ALTER TABLE sctp ADD KEY `sctp_dport` (`sctp_dport`); + + CREATE TABLE `icmp` ( `_icmp_id` bigint unsigned NOT NULL, `icmp_type` tinyint(3) unsigned default NULL,
@@ -231,10 +245,14 @@ CREATE SQL SECURITY INVOKER VIEW `ulog` AS mac_saddr as mac_saddr_str, mac_daddr as mac_daddr_str, mac_protocol as oob_protocol, - label as raw_label + label as raw_label, + sctp_sport, + sctp_dport, + sctp_csum FROM ulog2 LEFT JOIN tcp ON ulog2._id = tcp._tcp_id LEFT JOIN udp ON ulog2._id = udp._udp_id LEFT JOIN icmp ON ulog2._id = icmp._icmp_id LEFT JOIN mac ON ulog2.mac_id = mac._mac_id - LEFT JOIN hwhdr ON ulog2._id = hwhdr._hw_id LEFT JOIN icmpv6 ON ulog2._id = icmpv6._icmpv6_id; + LEFT JOIN hwhdr ON ulog2._id = hwhdr._hw_id LEFT JOIN icmpv6 ON ulog2._id = icmpv6._icmpv6_id + LEFT JOIN sctp ON ulog2._id = sctp._sctp_id; -- shortcuts
@@ -579,6 +597,20 @@ END $$ delimiter $$ +DROP PROCEDURE IF EXISTS PACKET_ADD_SCTP; +CREATE PROCEDURE PACKET_ADD_SCTP( + IN `id` int(10) unsigned, + IN `_sport` smallint(5) unsigned, + IN `_dport` smallint(5) unsigned, + IN `_csum` smallint(5) unsigned + ) +BEGIN + INSERT INTO sctp (_sctp_id, sctp_sport, sctp_dport, sctp_csum) VALUES + (id, _sport, _dport, _csum); +END +$$ + +delimiter $$ DROP PROCEDURE IF EXISTS PACKET_ADD_ICMP; CREATE PROCEDURE PACKET_ADD_ICMP( IN `id` int(10) unsigned,
@@ -699,7 +731,10 @@ CREATE FUNCTION INSERT_PACKET_FULL( mac_saddr varchar(32), mac_daddr varchar(32), mac_protocol smallint(5), - _label tinyint(4) unsigned + _label tinyint(4) unsigned, + sctp_sport smallint(5) unsigned, + sctp_dport smallint(5) unsigned, + sctp_csum int(10) unsigned ) RETURNS bigint unsigned READS SQL DATA BEGIN
@@ -714,6 +749,8 @@ BEGIN tcp_rst, tcp_syn, tcp_fin); ELSEIF _ip_protocol = 17 THEN CALL PACKET_ADD_UDP(@lastid, udp_sport, udp_dport, udp_len); + ELSEIF _ip_protocol = 132 THEN + CALL PACKET_ADD_SCTP(@lastid, sctp_sport, sctp_dport, sctp_csum); ELSEIF _ip_protocol = 1 THEN CALL PACKET_ADD_ICMP(@lastid, icmp_type, icmp_code, icmp_echoid, icmp_echoseq, icmp_gateway, icmp_fragmtu);
doc/pgsql-ulogd2.sql +39 -2
106 lines not on this page · raw message
Signature · 1 line
1.5.6.3
PATCH 8/18 Treat nice function return.
In reply to Eric Leblondgcc was warning that the return of the nice function should be treated. This patch adds an error message in case of failure.
--- src/ulogd.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
src/ulogd.c +7 -1
@@ -1129,7 +1129,13 @@ int main(int argc, char* argv[]) } } -nice (-1 ); + errno =0 ; +if (nice (-1 ) ==-1 ) { +if (errno !=0 ) +ulogd_log (ULOGD_ERROR ,"Could not nice process: %s\n" , +strerror (errno)); + } +if (daemonize){if (fork ()) {
Signature · 1 line
1.5.6.3
PATCH 9/18 Fix stop function of NFCT plugin.
In reply to Eric LeblondThis patch fixes some crashes in NFCT plugin that were triggered by the call of the destructor_nfct function (during stop).
--- input/flow/ulogd_inpflow_NFCT.c | 2 +- src/hash.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
input/flow/ulogd_inpflow_NFCT.c +1 -1
@@ -884,7 +884,7 @@ static int constructor_nfct(struct ulogd_pluginstance *upi)static int destructor_nfct (struct ulogd_pluginstance *pi) { -struct nfct_pluginstance *cpi = (void *) pi; +struct nfct_pluginstance *cpi = (void *) pi->private;int rc;hashtable_destroy (cpi->ct_active);
src/hash.c +4 -2
@@ -75,8 +75,10 @@ hashtable_create(int hashsize, int limit, int datasize,void hashtable_destroy (struct hashtable *h) { -hashtable_flush (h); -free (h); +if (h) { +hashtable_flush (h); +free (h); + } }void *hashtable_add (struct hashtable *table,void *data)
Signature · 1 line
1.5.6.3
PATCH 10/18 Don't free pluginstance when leaving
In reply to Eric LeblondIf we free pluginstance in the stop function we won't be able to iter anymore on the stack linked list.
--- input/packet/ulogd_inppkt_NFLOG.c | 2 -- input/packet/ulogd_inppkt_ULOG.c | 1 - 2 files changed, 0 insertions(+), 3 deletions(-)
input/packet/ulogd_inppkt_NFLOG.c +0 -2
@@ -569,8 +569,6 @@ static int stop(struct ulogd_pluginstance *pi)nflog_unbind_group (ui->nful_gh);nflog_close (ui->nful_h); -free (pi); -return 0 ; }
input/packet/ulogd_inppkt_ULOG.c +0 -1
@@ -309,7 +309,6 @@ static int fini(struct ulogd_pluginstance *pi)struct ulog_input *ui = (struct ulog_input *)pi->private;ulogd_unregister_fd (&ui->ulog_fd); -free (pi);return 0 ; }
Signature · 1 line
1.5.6.3
PATCH 11/18 Fix minor memory leak in NFLOG plugin.
In reply to Eric LeblondThis patch fix a minor memory leak at NFLOG plugin exit.
--- input/packet/ulogd_inppkt_NFLOG.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
input/packet/ulogd_inppkt_NFLOG.c +2 -0
@@ -569,6 +569,8 @@ static int stop(struct ulogd_pluginstance *pi)nflog_unbind_group (ui->nful_gh);nflog_close (ui->nful_h); +free (ui->nfulog_buf); +return 0 ; }
Signature · 1 line
1.5.6.3
PATCH 12/18 Call pluginstance stop function when exiting
In reply to Eric LeblondThe stop function of plugin was not called when ulogd2 was preparing to quit. This patch adds a call to stop for all plugins in each stack and free pluginstance.
--- src/ulogd.c | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-)
src/ulogd.c +25 -1
@@ -958,18 +958,42 @@ static void deliver_signal_pluginstances(int signal) } } +static void stop_pluginstances () +{ +struct ulogd_pluginstance_stack *stack; +struct ulogd_pluginstance *pi, *npi; + +llist_for_each_entry (stack, &ulogd_pi_stacks, stack_list) { +llist_for_each_entry_safe (pi, npi, &stack->list, list) { +if (((pi->plugin->priv_size ==0 ) || pi->private[0 ]) + && *pi->plugin->stop) { +ulogd_log (ULOGD_DEBUG ,"calling stop for %s\n" , + pi->plugin->name); + (*pi->plugin->stop)(pi); + pi->private[0 ] =0 ; + } +free (pi); + } + } +} +static void sigterm_handler (int signal) { - +ulogd_log (ULOGD_NOTICE ,"sigterm received, exiting\n" );deliver_signal_pluginstances (signal); +stop_pluginstances (); +if (logfile !=NULL && logfile != stdout) {fclose (logfile); logfile =NULL ; } +if (ulogd_logfile) +free (ulogd_logfile); +exit (0 ); }
Signature · 1 line
1.5.6.3
PATCH 13/18 Add SIGINT to list of terminal signal.
In reply to Eric LeblondThis patch modifies ulogd to intercept SIGINT signal and quit nicely when this signal is received.
--- src/ulogd.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
src/ulogd.c +2 -1
@@ -980,7 +980,7 @@ static void stop_pluginstances()static void sigterm_handler (int signal) { -ulogd_log (ULOGD_NOTICE ,"sigterm received, exiting\n" ); +ulogd_log (ULOGD_NOTICE ,"Terminal signal received, exiting\n" );deliver_signal_pluginstances (signal);
@@ -1173,6 +1173,7 @@ int main(int argc, char* argv[]) }signal (SIGTERM , &sigterm_handler); +signal (SIGINT , &sigterm_handler);signal (SIGHUP , &signal_handler);signal (SIGALRM , &signal_handler);signal (SIGUSR1 , &signal_handler);
Signature · 1 line
1.5.6.3
PATCH 14/18 Unload plugins when quitting.
In reply to Eric LeblondThis patch adds unloading of plugins (call dlclose()) in ulogd2. This make valgrind happy and will be useful for daemon live reconfiguration.
--- include/ulogd/ulogd.h | 8 ++++++++ src/ulogd.c | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletions(-)
include/ulogd/ulogd.h +8 -0
@@ -187,6 +187,14 @@ static inline void *ikey_get_ptr(struct ulogd_key *key)struct ulogd_pluginstance_stack ;struct ulogd_pluginstance ; + +struct ulogd_plugin_handle { +/* global list of plugins */ +struct llist_head list; +void *handle; +}; + +struct ulogd_plugin {/* global list of plugins */ struct llist_head list;
src/ulogd.c +20 -1
@@ -83,6 +83,8 @@ static int info_mode = 0;/* linked list for all registered plugins */ static LLIST_HEAD (ulogd_plugins); +/* linked list for all plugins handle */ +static LLIST_HEAD (ulogd_plugins_handle);static LLIST_HEAD (ulogd_pi_stacks);
@@ -580,11 +582,17 @@ pluginstance_alloc_init(struct ulogd_plugin *pl, char *pi_id,/* plugin loader to dlopen() a plugins */ static int load_plugin (const char *file) { -if (!dlopen (file,RTLD_NOW )) { +void * handle; +struct ulogd_plugin_handle *ph; +if ((handle =dlopen (file,RTLD_NOW )) ==NULL ) {ulogd_log (ULOGD_ERROR ,"load_plugin: '%s': %s\n" , file,dlerror ());return -1 ; } + + ph = (struct ulogd_plugin_handle *)calloc (1 ,sizeof (*ph)); + ph->handle = handle; +llist_add (&ph->list, &ulogd_plugins_handle);return 0 ; }
@@ -977,6 +985,15 @@ static void stop_pluginstances() } } +static void unload_plugins () +{ +struct ulogd_plugin_handle *ph, *nph; +llist_for_each_entry_safe (ph, nph, &ulogd_plugins_handle, list) { +dlclose (ph->handle); +free (ph); + } +} +static void sigterm_handler (int signal) {
@@ -986,6 +1003,8 @@ static void sigterm_handler(int signal)stop_pluginstances (); +unload_plugins (); +if (logfile !=NULL && logfile != stdout) {fclose (logfile); logfile =NULL ;
Signature · 1 line
1.5.6.3
PATCH 15/18 Introduce config_stop() function
In reply to Eric LeblondThis patch adds the config_stop function which is in charge of releasing ressources allocated for configuration file parsing.
--- include/ulogd/conffile.h | 3 +++ src/conffile.c | 4 ++++ src/ulogd.c | 2 ++ 3 files changed, 9 insertions(+), 0 deletions(-)
include/ulogd/conffile.h +3 -0
@@ -67,4 +67,7 @@ int config_register_file(const char *file);/* parse the config file */ int config_parse_file (const char *section,struct config_keyset *kset); +/* release ressource allocated by config file handling */ +void config_stop (); +#endif /* ifndef _CONFFILE_H */
src/conffile.c +4 -0
@@ -222,3 +222,7 @@ cpf_error:return err; } +void config_stop () +{ +free (fname); +}
src/ulogd.c +2 -0
@@ -1013,6 +1013,8 @@ static void sigterm_handler(int signal)if (ulogd_logfile)free (ulogd_logfile); +config_stop (); +exit (0 ); }
Signature · 1 line
1.5.6.3
PATCH 16/18 Free stacks when exiting.
In reply to Eric LeblondThis patch modifies ulogd2 to have it free the stacks when leaving.
--- src/ulogd.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
src/ulogd.c +12 -0
@@ -994,6 +994,16 @@ static void unload_plugins() } } +static void stop_stack () +{ +struct ulogd_pluginstance_stack *stack, *nstack; + +llist_for_each_entry_safe (stack, nstack, &ulogd_pi_stacks, stack_list) { +free (stack); + } +} + +static void sigterm_handler (int signal) {
@@ -1003,6 +1013,8 @@ static void sigterm_handler(int signal)stop_pluginstances (); +stop_stack (); +unload_plugins ();if (logfile !=NULL && logfile != stdout) {
Signature · 1 line
1.5.6.3
PATCH 17/18 Fix memory leak in destructor_nfct().
In reply to Eric LeblondThis patch fixes a memroy leak in the destructor function which was not releasing the memory allocated for each connection tracking entry.
--- input/flow/ulogd_inpflow_NFCT.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
input/flow/ulogd_inpflow_NFCT.c +10 -0
@@ -692,6 +692,13 @@ static int read_cb_nfct(int fd, unsigned int what, void *param)return 0 ; } +static int do_free (void *data1,void *data2) +{ +struct ct_timestamp *ts = data2; +free (ts->ct); +} + +static int do_purge (void *data1,void *data2) {int ret;
@@ -887,6 +894,9 @@ static int destructor_nfct(struct ulogd_pluginstance *pi)struct nfct_pluginstance *cpi = (void *) pi->private;int rc; +/* free existent entries */ +hashtable_iterate (cpi->ct_active,NULL , do_free); +hashtable_destroy (cpi->ct_active); rc =nfct_close (cpi->cth);
Signature · 1 line
1.5.6.3
PATCH 18/18 Add valgrind compilation option.
In reply to Eric LeblondValgrind messages are obscur when the plugins are unloaded. This patch adds a macro that can be used to desactivate unloading. To use it, you have to specify 'CPPFLAGS=-DDEBUG_VALGRIND' on configure line.
--- src/ulogd.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
src/ulogd.c +4 -0
@@ -985,6 +985,7 @@ static void stop_pluginstances() } } +#ifndef DEBUG_VALGRIND static void unload_plugins () {struct ulogd_plugin_handle *ph, *nph;
@@ -993,6 +994,7 @@ static void unload_plugins() free(ph); } } +#endif static void stop_stack () {
@@ -1015,7 +1017,9 @@ static void sigterm_handler(int signal)stop_stack (); +#ifndef DEBUG_VALGRIND unload_plugins (); +#endif if (logfile !=NULL && logfile != stdout) {fclose (logfile);
Signature · 1 line
1.5.6.3
Eric Leblond
AppliedHi,
I've applied all patches to Netfilter's ulogd2 git tree.
BR,
Signature · 3 lines
Éric Leblond <[email protected]> INL, http://www.inl.fr/ NuFW, http://www.nufw.org