[Devel,RH7,3/3] netfilter: rectify ebtlog inside CT

Submitted by Dmitry Safonov on Dec. 21, 2016, 8:48 a.m.

Details

Message ID 20161221084835.32072-4-dsafonov@virtuozzo.com
State New
Series "iptables LOG in CT"
Headers show

Commit Message

Dmitry Safonov Dec. 21, 2016, 8:48 a.m.
Print ebtables LOG into VE's log buffer.

Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
---
 net/bridge/netfilter/ebt_log.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

Patch hide | download patch | download mbox

diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index dc724cdfe76d..d13ef510fdc6 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -51,7 +51,7 @@  struct arppayload
 };
 
 static void
-print_ports(const struct sk_buff *skb, uint8_t protocol, int offset)
+print_ports(const struct sk_buff *skb, uint8_t protocol, int offset, struct ve_struct *ve)
 {
 	if (protocol == IPPROTO_TCP ||
 	    protocol == IPPROTO_UDP ||
@@ -64,10 +64,10 @@  print_ports(const struct sk_buff *skb, uint8_t protocol, int offset)
 		pptr = skb_header_pointer(skb, offset,
 					  sizeof(_ports), &_ports);
 		if (pptr == NULL) {
-			printk(" INCOMPLETE TCP/UDP header");
+			ve_log_printk(ve, " INCOMPLETE TCP/UDP header");
 			return;
 		}
-		printk(" SPT=%u DPT=%u", ntohs(pptr->src), ntohs(pptr->dst));
+		ve_log_printk(ve, " SPT=%u DPT=%u", ntohs(pptr->src), ntohs(pptr->dst));
 	}
 }
 
@@ -78,13 +78,10 @@  ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
 	       const char *prefix)
 {
 	unsigned int bitmask;
-
-	/* FIXME: Disabled from containers until syslog ns is supported */
-	if (!net_eq(net, &init_net))
-		return;
+	struct ve_struct *ve = net->owner_ve;
 
 	spin_lock_bh(&ebt_log_lock);
-	printk(KERN_SOH "%c%s IN=%s OUT=%s MAC source = %pM MAC dest = %pM proto = 0x%04x",
+	ve_log_printk(ve, KERN_SOH "%c%s IN=%s OUT=%s MAC source = %pM MAC dest = %pM proto = 0x%04x",
 	       '0' + loginfo->u.log.level, prefix,
 	       in ? in->name : "", out ? out->name : "",
 	       eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
@@ -102,12 +99,12 @@  ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
 
 		ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
 		if (ih == NULL) {
-			printk(" INCOMPLETE IP header");
+			ve_log_printk(ve, " INCOMPLETE IP header");
 			goto out;
 		}
-		printk(" IP SRC=%pI4 IP DST=%pI4, IP tos=0x%02X, IP proto=%d",
+		ve_log_printk(ve, " IP SRC=%pI4 IP DST=%pI4, IP tos=0x%02X, IP proto=%d",
 		       &ih->saddr, &ih->daddr, ih->tos, ih->protocol);
-		print_ports(skb, ih->protocol, ih->ihl*4);
+		print_ports(skb, ih->protocol, ih->ihl*4, ve);
 		goto out;
 	}
 
@@ -122,16 +119,16 @@  ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
 
 		ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
 		if (ih == NULL) {
-			printk(" INCOMPLETE IPv6 header");
+			ve_log_printk(ve, " INCOMPLETE IPv6 header");
 			goto out;
 		}
-		printk(" IPv6 SRC=%pI6 IPv6 DST=%pI6, IPv6 priority=0x%01X, Next Header=%d",
+		ve_log_printk(ve, " IPv6 SRC=%pI6 IPv6 DST=%pI6, IPv6 priority=0x%01X, Next Header=%d",
 		       &ih->saddr, &ih->daddr, ih->priority, ih->nexthdr);
 		nexthdr = ih->nexthdr;
 		offset_ph = ipv6_skip_exthdr(skb, sizeof(_iph), &nexthdr, &frag_off);
 		if (offset_ph == -1)
 			goto out;
-		print_ports(skb, nexthdr, offset_ph);
+		print_ports(skb, nexthdr, offset_ph, ve);
 		goto out;
 	}
 #endif
@@ -144,10 +141,10 @@  ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
 
 		ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
 		if (ah == NULL) {
-			printk(" INCOMPLETE ARP header");
+			ve_log_printk(ve, " INCOMPLETE ARP header");
 			goto out;
 		}
-		printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
+		ve_log_printk(ve, " ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
 		       ntohs(ah->ar_hrd), ntohs(ah->ar_pro),
 		       ntohs(ah->ar_op));
 
@@ -162,15 +159,15 @@  ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
 			ap = skb_header_pointer(skb, sizeof(_arph),
 						sizeof(_arpp), &_arpp);
 			if (ap == NULL) {
-				printk(" INCOMPLETE ARP payload");
+				ve_log_printk(ve, " INCOMPLETE ARP payload");
 				goto out;
 			}
-			printk(" ARP MAC SRC=%pM ARP IP SRC=%pI4 ARP MAC DST=%pM ARP IP DST=%pI4",
+			ve_log_printk(ve, " ARP MAC SRC=%pM ARP IP SRC=%pI4 ARP MAC DST=%pM ARP IP DST=%pI4",
 					ap->mac_src, ap->ip_src, ap->mac_dst, ap->ip_dst);
 		}
 	}
 out:
-	printk("\n");
+	ve_log_printk(ve, "\n");
 	spin_unlock_bh(&ebt_log_lock);
 
 }