| 1 |
#ifndef __NETFILTER_C__ |
| 2 |
#define __NETFILTER_C__ |
| 3 |
|
| 4 |
#ifndef STAPCONF_NF_REGISTER_HOOK |
| 5 |
|
| 6 |
// The following kernel commit removed nf_register_hook(), which the |
| 7 |
// netfilter probes use: |
| 8 |
// |
| 9 |
// commit cf56c2f892a8a1870a8358114ad896772da7543a |
| 10 |
// Author: Florian Westphal <[email protected]> |
| 11 |
// Date: Thu Jul 6 23:17:44 2017 +0200 |
| 12 |
// |
| 13 |
// netfilter: remove old pre-netns era hook api |
| 14 |
// |
| 15 |
// no more users in the tree, remove this. |
| 16 |
// |
| 17 |
// The old api is racy wrt. module removal, all users have been converted |
| 18 |
// to the netns-aware api. |
| 19 |
// |
| 20 |
// The old api pretended we still have global hooks but that has not been |
| 21 |
// true for a long time. |
| 22 |
// |
| 23 |
// So, we'll add our own nf_register_hook(), that pretends that global |
| 24 |
// hooks exist. |
| 25 |
|
| 26 |
#include <net/net_namespace.h> |
| 27 |
#include <linux/netfilter.h> |
| 28 |
#include <linux/errno.h> |
| 29 |
|
| 30 |
static int nf_register_hook(struct nf_hook_ops *reg) |
| 31 |
{ |
| 32 |
struct net *net, *last; |
| 33 |
int ret = 0; |
| 34 |
|
| 35 |
for_each_net(net) { |
| 36 |
ret = nf_register_net_hook(net, reg); |
| 37 |
if (ret && ret != -ENOENT) |
| 38 |
goto rollback; |
| 39 |
} |
| 40 |
return 0; |
| 41 |
|
| 42 |
rollback: |
| 43 |
last = net; |
| 44 |
for_each_net(net) { |
| 45 |
if (net == last) |
| 46 |
break; |
| 47 |
nf_unregister_net_hook(net, reg); |
| 48 |
} |
| 49 |
return ret; |
| 50 |
} |
| 51 |
|
| 52 |
static void nf_unregister_hook(struct nf_hook_ops *reg) |
| 53 |
{ |
| 54 |
struct net *net; |
| 55 |
|
| 56 |
for_each_net(net) { |
| 57 |
nf_unregister_net_hook(net, reg); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
#endif // STAPCONF_NF_REGISTER_HOOK |
| 62 |
#endif // __NETFILTER_C__ |