fib6_notifier.c 1.43 KB
Newer Older
1 2 3
#include <linux/notifier.h>
#include <linux/socket.h>
#include <linux/kernel.h>
4
#include <linux/export.h>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <net/net_namespace.h>
#include <net/fib_notifier.h>
#include <net/netns/ipv6.h>
#include <net/ip6_fib.h>

int call_fib6_notifier(struct notifier_block *nb, struct net *net,
		       enum fib_event_type event_type,
		       struct fib_notifier_info *info)
{
	info->family = AF_INET6;
	return call_fib_notifier(nb, net, event_type, info);
}

int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
			struct fib_notifier_info *info)
{
	info->family = AF_INET6;
	return call_fib_notifiers(net, event_type, info);
}

static unsigned int fib6_seq_read(struct net *net)
{
27
	return fib6_tables_seq_read(net) + fib6_rules_seq_read(net);
28 29 30 31
}

static int fib6_dump(struct net *net, struct notifier_block *nb)
{
32 33 34 35 36 37 38
	int err;

	err = fib6_rules_dump(net, nb);
	if (err)
		return err;

	return fib6_tables_dump(net, nb);
39 40 41 42 43 44
}

static const struct fib_notifier_ops fib6_notifier_ops_template = {
	.family		= AF_INET6,
	.fib_seq_read	= fib6_seq_read,
	.fib_dump	= fib6_dump,
45
	.owner		= THIS_MODULE,
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
};

int __net_init fib6_notifier_init(struct net *net)
{
	struct fib_notifier_ops *ops;

	ops = fib_notifier_ops_register(&fib6_notifier_ops_template, net);
	if (IS_ERR(ops))
		return PTR_ERR(ops);
	net->ipv6.notifier_ops = ops;

	return 0;
}

void __net_exit fib6_notifier_exit(struct net *net)
{
	fib_notifier_ops_unregister(net->ipv6.notifier_ops);
}