Skip to content

Commit 69b34fb

Browse files
Gao fengummakynes
authored andcommitted
netfilter: xt_LOG: add net namespace support for xt_LOG
Add pernet support to xt_LOG by means of the new nf_log_set function added in (30e0c6a netfilter: nf_log: prepare net namespace support for loggers). Since syslog ns has yet not been implemented, we don't want the containers to DDOS host's syslogd. So only enable ebt_log only from init_net and wait for syslog ns support Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 7d27892 commit 69b34fb

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

net/netfilter/xt_LOG.c

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,14 @@ ipt_log_packet(u_int8_t pf,
474474
const struct nf_loginfo *loginfo,
475475
const char *prefix)
476476
{
477-
struct sbuff *m = sb_open();
477+
struct sbuff *m;
478+
struct net *net = dev_net(in ? in : out);
479+
480+
/* FIXME: Disabled from containers until syslog ns is supported */
481+
if (!net_eq(net, &init_net))
482+
return;
483+
484+
m = sb_open();
478485

479486
if (!loginfo)
480487
loginfo = &default_loginfo;
@@ -798,7 +805,14 @@ ip6t_log_packet(u_int8_t pf,
798805
const struct nf_loginfo *loginfo,
799806
const char *prefix)
800807
{
801-
struct sbuff *m = sb_open();
808+
struct sbuff *m;
809+
struct net *net = dev_net(in ? in : out);
810+
811+
/* FIXME: Disabled from containers until syslog ns is supported */
812+
if (!net_eq(net, &init_net))
813+
return;
814+
815+
m = sb_open();
802816

803817
if (!loginfo)
804818
loginfo = &default_loginfo;
@@ -893,23 +907,55 @@ static struct nf_logger ip6t_log_logger __read_mostly = {
893907
};
894908
#endif
895909

910+
static int __net_init log_net_init(struct net *net)
911+
{
912+
nf_log_set(net, NFPROTO_IPV4, &ipt_log_logger);
913+
#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
914+
nf_log_set(net, NFPROTO_IPV6, &ip6t_log_logger);
915+
#endif
916+
return 0;
917+
}
918+
919+
static void __net_exit log_net_exit(struct net *net)
920+
{
921+
nf_log_unset(net, &ipt_log_logger);
922+
#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
923+
nf_log_unset(net, &ip6t_log_logger);
924+
#endif
925+
}
926+
927+
static struct pernet_operations log_net_ops = {
928+
.init = log_net_init,
929+
.exit = log_net_exit,
930+
};
931+
896932
static int __init log_tg_init(void)
897933
{
898934
int ret;
899935

936+
ret = register_pernet_subsys(&log_net_ops);
937+
if (ret < 0)
938+
goto err_pernet;
939+
900940
ret = xt_register_targets(log_tg_regs, ARRAY_SIZE(log_tg_regs));
901941
if (ret < 0)
902-
return ret;
942+
goto err_target;
903943

904944
nf_log_register(NFPROTO_IPV4, &ipt_log_logger);
905945
#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
906946
nf_log_register(NFPROTO_IPV6, &ip6t_log_logger);
907947
#endif
908948
return 0;
949+
950+
err_target:
951+
unregister_pernet_subsys(&log_net_ops);
952+
err_pernet:
953+
return ret;
909954
}
910955

911956
static void __exit log_tg_exit(void)
912957
{
958+
unregister_pernet_subsys(&log_net_ops);
913959
nf_log_unregister(&ipt_log_logger);
914960
#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
915961
nf_log_unregister(&ip6t_log_logger);

0 commit comments

Comments
 (0)