Skip to contentSkip to conversation

RFC containerized syslog and iptable log dispatching (working stage)

PATCH New Jean-Marc Pigeon 1 participant 1 message Feb 23, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC containerized syslog and iptable log dispatching (working stage)

Capability to redirect iptable log, in the right containerized syslog_ns, is now fully working.

Tried my best to have a very minimal foot-print.

BEWARE: patch not done for IPV6 (I can't test it), you are welcome to do it.

---
 include/linux/netdevice.h    |    2 +
 include/linux/syslog.h       |    8 +++
 kernel/syslog.c              |  140 +++++++++++++++++++++++++++++++++++++++---
 net/core/rtnetlink.c         |    3 +
 net/ipv4/netfilter/ipt_LOG.c |   11 +++
 5 files changed, 154 insertions(+), 10 deletions(-)
include/linux/netdevice.h +2 -0
index a3fccc8..c323463 100644
@@ -918,6 +918,8 @@ struct net_device {
 	/* Network namespace this network device is inside */
 	struct net		*nd_net;
 #endif
+	/* to assign a syslog chanel according device ownership	*/
+	pid_t			syslog_ns_pid;
 
 	/* mid-layer private */
 	void			*ml_priv;
include/linux/syslog.h +8 -0
index 9fbe190..2188f09 100644
@@ -44,15 +44,23 @@ static inline void put_syslog_ns(struct syslog_ns *ns)
 #ifdef	CONFIG_PRINTK
 extern struct syslog_ns *current_syslog_ns(void);
 extern struct syslog_ns *switch_syslog_ns(struct syslog_ns *syslog_ns);
+extern struct syslog_ns *find_syslog_ns_bypid(pid_t pid);
 #else
 static inline syslog_ns *current_syslog_ns(void)
 {
 	return 0;
 }
+
 static inline struct syslog_ns *switch_syslog_ns(struct syslog_ns *syslog_ns)
 {
 	return syslog_ns;
 }
+
+static inline syslog_ns *find_syslog_ns_bypid(pid_t pid)
+
+{
+	return 0;
+}
 #endif
 
 #endif /* _LINUX_SYSLOG_H */
kernel/syslog.c +130 -10

183 lines not on this page · raw message

net/core/rtnetlink.c +3 -0
index 794bcb8..e41bc93 100644
@@ -775,6 +775,9 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
 			err = PTR_ERR(net);
 			goto errout;
 		}
+		if (dev)
+			dev->syslog_ns_pid = nla_get_u32(tb[IFLA_NET_NS_PID]);
+
 		err = dev_change_net_namespace(dev, net, ifname);
 		put_net(net);
 		if (err)
net/ipv4/netfilter/ipt_LOG.c +11 -0
index ee128ef..7e1467d 100644
@@ -14,6 +14,7 @@
 #include <linux/spinlock.h>
 #include <linux/skbuff.h>
 #include <linux/ip.h>
+#include <linux/syslog.h>
 #include <net/icmp.h>
 #include <net/udp.h>
 #include <net/tcp.h>
@@ -382,6 +383,15 @@ ipt_log_packet(u_int8_t pf,
 	       const struct nf_loginfo *loginfo,
 	       const char *prefix)
 {
+
+	struct syslog_ns	*syslog_ns;
+
+
+	syslog_ns = (struct syslog_ns *)0;
+	if (skb->dev) 	/*another syslog_ns possible?	*/
+		syslog_ns = find_syslog_ns_bypid(skb->dev->syslog_ns_pid);
+	syslog_ns = switch_syslog_ns(syslog_ns);
+
 	if (!loginfo)
 		loginfo = &default_loginfo;
 
@@ -422,6 +432,7 @@ ipt_log_packet(u_int8_t pf,
 	dump_packet(loginfo, skb, 0);
 	printk("\n");
 	spin_unlock_bh(&log_lock);
+	(void) switch_syslog_ns(syslog_ns);
 }
 
 static unsigned int
Signature · 1 line
1.6.6