File: netfilter.c

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (62 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef __NETFILTER_C__
#define __NETFILTER_C__

#ifndef STAPCONF_NF_REGISTER_HOOK

// The following kernel commit removed nf_register_hook(), which the
// netfilter probes use:
//
//   commit cf56c2f892a8a1870a8358114ad896772da7543a
//   Author: Florian Westphal <fw@strlen.de>
//   Date:   Thu Jul 6 23:17:44 2017 +0200
//   
//       netfilter: remove old pre-netns era hook api
//       
//       no more users in the tree, remove this.
//       
//       The old api is racy wrt. module removal, all users have been converted
//       to the netns-aware api.
//       
//       The old api pretended we still have global hooks but that has not been
//       true for a long time.
//
// So, we'll add our own nf_register_hook(), that pretends that global
// hooks exist.

#include <net/net_namespace.h>
#include <linux/netfilter.h>
#include <linux/errno.h>

static int nf_register_hook(struct nf_hook_ops *reg)
{
	struct net *net, *last;
	int ret = 0;

	for_each_net(net) {
		ret = nf_register_net_hook(net, reg);
		if (ret && ret != -ENOENT)
			goto rollback;
	}
	return 0;

rollback:
	last = net;
	for_each_net(net) {
		if (net == last)
			break;
		nf_unregister_net_hook(net, reg);
	}
	return ret;
}

static void nf_unregister_hook(struct nf_hook_ops *reg)
{
	struct net *net;

	for_each_net(net) {
		nf_unregister_net_hook(net, reg);
	}
}

#endif	// STAPCONF_NF_REGISTER_HOOK
#endif	// __NETFILTER_C__