libnfnetlink_conntrack encapsulation issues
I'm reworking some patches from conntrack 0.4.2 to the latest conntrack and I am getting badly bitten by a few problems of encapsulation and over seperation between user and kernel space.
Problem 1:
One of my requirements is to combine CT_DUMP with CT_EVENT, so that I get regular events but also an inline dump based on a signal (blah blah blah). Inline (over the same socket) is important as it makes synchronzing the dump with events a little easier.
Of course most of this won't belong in libnetlink_conntrack but in some conntrack derivative, but the encapsulation of nfct_handle spoils this.
Specifically, I need such behaviours as requesting the conntrack table dump but without the nfnl_listen tacked on the end, for example (simplified fragment):
int nfct_dump_conntrack_table_request(struct nfct_handle *cth, int flags, int family)
{
int err, msg;
struct nfnlhdr req;
memset(&req, 0, sizeof(req));
/* This is not important until nfnl_listen we will set it again
by then
cth->handler = nfct_conntrack_netlink_handler;
*/
msg = flags;
nfnl_fill_hdr(cth->nfnlssh_ct, &req.nlh, 0, family, 0,
msg,NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST|NLM_F_DUMP);
err = nfnl_send(cth->nfnlh, &req.nlh);
return err;
}int nfct_dump_event_conntrack(struct nfct_handle *cth, int family)
{
struct sigaction sa;
struct sigaction oldint;
sa.sa_handler = signal_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
setlinebuf(stdout);
sigaction(SIGUSR1, &sa, &oldint);
if
(nfct_dump_conntrack_table_requestl(cth,IPCTNL_MSG_CT_GET_CTRZERO_EXTRA,family)<0)
{
exit_error(OTHER_PROBLEM, "Can't request initial dump");
break;
}
/* Break this open later to do our own handler and own callback */
return nfct_event_conntrack(nfct_handle);
}Of course I'd rather do this duplicating as little of libnetlink_conntrack as possible, but this means libnetlink_conntrack needs to open up its primatives a lttle more. The reason I need my own handler too is because I'm sending back extra tuples including layer7 information (I've submitted patches for this to the layer7 mailing list)
Also, as well as IPCTNL_MSG_CT_GET_CTRZERO in libnetfilter_conntrack/include/libnetfilter_conntrack/linux_nfnetlink_conntrack.h
I have IPCTNL_MSG_CT_GET_CTRZERO_EXTRA, which is an alternate message
to pass to the kernel to zero another class of counters. Again, the libnetlink_conntrack library calls don't permit passing individual messages, making libnetlink_conntrack tightly coupled to a specific kernel and requiring that the kernel capabilities be known to libnetlink_conntrack - for example, do we need to change libnetlink_conntrack every time a new type of data can be dumped? (e.g. layer7?)
Problem 2
autogen.sh
(mild issue first, not your fault anyway)
Of course my message is defined in my kernel headers which autogen.sh tries to copy accross - except that I am now using the make -o option for the kernel which means that build header files like autoconf.h, compile.h and version.h are linked to from /lib/modules/uname -r/build but none of the source header files are. For now I can copy the header file by hand but I wonder if anyone has a more general solution to this. I guess that the make process ought to write symlinks to any include dirs to the source.
However (big problems), when I make autogen copy my version of nfnetlink_conntrack.h, compiles fail on lack of: CTA_EXPECT_QUEUENR which I don't find available in any of the kernel sources I have; so which kernel is being tracked for libnetfilter_conntrack? The only useful reference google can find is a February chat session which indicates that linux_nfnetlink_conntrack.h is being kept in SVN so where does the idea of CTA_EXPECT_QUEUENR come from?
In fact I find that despite the assurances in autogen,sh, linux_nfnetlink_conntrack.h IS being kept in CVN and that the only solution the chatlogs recommend is to revert linux_nfnetlink_conntrack.h to the supplied one? What?
I sometimes wonder if it is time to stop sharing enums like this between kernel and user space and make text labels out of them which applications can resolve into numbers by asking the kernel as they are executed.
Sam
aggg Re: libnfnetlink_conntrack encapsulation issues
Not only is linux_nfnetlink_conntrack.h from SVN and not any kernel, it even ignores the kernel config so such ifdef's as:
enum ctattr_type {
CTA_UNSPEC,
CTA_TUPLE_ORIG,
CTA_TUPLE_REPLY,
CTA_STATUS,
CTA_PROTOINFO,
CTA_HELP,
CTA_NAT_SRC,
#define CTA_NAT CTA_NAT_SRC /* backwards compatibility */
CTA_TIMEOUT,
CTA_MARK,
CTA_COUNTERS_ORIG,
CTA_COUNTERS_REPLY,
CTA_USE,
CTA_ID,
CTA_NAT_DST,
#if defined(CONFIG_IP_NF_MATCH_LAYER7) ||
defined(CONFIG_IP_NF_MATCH_LAYER7_MODULE)
CTA_L7,#endif /* LAYER7 */
#ifdef CONFIG_IP_NF_CT_LINKLAYER
CTA_LINKLAYER,
#endif /* LINKLAYER */
...
...
...
are ignored, resulting in a totally different enum anyway.
I see now that obviously these extra enum members should not be defined with ifdef, and it fact it makes a lot of sense, otherwise rebuilding with a new match enabled as a module would change the enum definition for that module but for nothing else.
BUT if libnetlink_conntrack is going to be reading kernel files, ought it not to read in the kernel config too?
oy oy oy. Sorry to be so dumb, but I don't think we've hit the right kernel/userspace solution yet.
I'm reminded of the windows make_atom call which allows you or anyone to
supply a string and get the same number back every time, I wonder if we
need that instead of enums.
Sam
Re: aggg Re: libnfnetlink_conntrack encapsulation issues
Quoted 22 lines · Amin Azez
Not only is
linux_nfnetlink_conntrack.hfrom SVN and not any kernel, it even ignores the kernel config so such ifdef's as:enum
ctattr_type{
CTA_UNSPEC,
CTA_TUPLE_ORIG,
CTA_TUPLE_REPLY,
CTA_STATUS,
CTA_PROTOINFO,
CTA_HELP,
CTA_NAT_SRC,#define CTA_NAT CTA_NAT_SRC /* backwards compatibility */ CTA_TIMEOUT, CTA_MARK, CTA_COUNTERS_ORIG, CTA_COUNTERS_REPLY, CTA_USE, CTA_ID, CTA_NAT_DST, #if defined(CONFIG_IP_NF_MATCH_LAYER7) || defined(CONFIG_IP_NF_MATCH_LAYER7_MODULE) CTA_L7,
Quoted 7 lines
#endif /* LAYER7 */
#ifdefCONFIG_IP_NF_CT_LINKLAYER
CTA_LINKLAYER,
#endif /* LINKLAYER */
...
...
...
WTF is this? Its not from SVN, it appears the layer7 match does some bad hacks here. It looks like a really dumb idea, this will break once we add new attributes. Not sure why a match would need ctnetlink attributes.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: aggg Re: libnfnetlink_conntrack encapsulation issues
Quoted 10 lines · Amin Azez
* Patrick McHardy wrote, On 27/07/06 15:00:
Quoted 2 lines
it appears the layer7 match does some
bad hacks here.Thats my layer7 stuff.
I recognize that ifdef's here are no good because the file is used for userspace, which doesn't solve the general problem of adding conntrack attributes generally (which I've been doing for the last 15 months). The current mechanism effectively ensures that this cannot happen (sadly)
One way to add new stuff is to get your patch into the kernel. Other than that its hard, I agree. ifdefs are not a good idea because following members don't have a constant value anymore.
Quoted 9 lines
Quoted 4 lines
It looks like a really dumb idea, this will break
once we add new attributes. Not sure why a match would need ctnetlink attributes.Some matches (like layer7) store state which is output via
/proc/net/ip_conntrack, I also need it as part of conntrack updates. I like receiving a conntrack update when the layer7 is detected, for instance.
A match shouldn't do that - what kind of state does it store? Can't you just use your match and combine it with CONNMARK?
Quoted 1 line
I also output the link layer mac addresses as part of conntrack dumps/
The LL address is not part of the conntrack entry and can change at any time, so it doesn't belong in ctnetlink.
Re: aggg Re: libnfnetlink_conntrack encapsulation issues
* Patrick McHardy wrote, On 27/07/06 15:32:
Quoted 11 lines
Quoted 9 lines · Amin Azez
* Patrick McHardy wrote, On 27/07/06 15:00:
Quoted 2 lines
it appears the layer7 match does some
bad hacks here.Thats my layer7 stuff.
I recognize that ifdef's here are no good because the file is used for userspace, which doesn't solve the general problem of adding conntrack attributes generally (which I've been doing for the last 15 months). The current mechanism effectively ensures that this cannot happen (sadly)
Quoted 3 lines
One way to add new stuff is to get your patch into the kernel. Other than that its hard, I agree. ifdefs are not a good idea because following members don't have a constant value anymore.
Indeed. Layer7 has been around some time, I guess I will attempt to get CTA_L7 into that file in the official kernel so that those who use the L7 match can get L7 info via contrack /if they want/.
Quoted 8 lines
Quoted 5 lines
Some matches (like layer7) store state which is output via
/proc/net/ip_conntrack, I also need it as part of conntrack updates. I like receiving a conntrack update when the layer7 is detected, for instance.A match shouldn't do that - what kind of state does it store? Can't you just use your match and combine it with CONNMARK?
Err... it stores the layer7 pattern that was matched against the packets. So you can recognize a flow as being HTTP or SMTP or DNS etc, by regexing the packets. It only checks the first few packets in each direction of the flow, but having matched, the name of the matching pattern becomes part of the conntrack, and the iptables module can then test this - so you could set a certain connmark based on the ip addresses in combination with some layer7 type; so that HTTP - no matter what the port - could all have a higher priority. This is visible from /proc/net/ip_conntrack
Quoted 4 lines
Quoted 1 line
I also output the link layer mac addresses as part of conntrack dumps/
The LL address is not part of the conntrack entry and can change at any time, so it doesn't belong in ctnetlink.
I won't argue on this one, it's merely one of my uses, with the option to perform a ctnetlink update when the mac addresses change.
The bigger problem which I guess you answered is, how "new" ctnetlink attributes should be registered and used; how near an extensible framework (which is what I *thought* libnetlink_conntrack was for) and how much is just abstraction from the kernel (which it seems *is* what libnetlink_conntrack is for).
This other problem was how much of libnetlink_conntrack I am rewriting so that I can vary ever so slightly the conntrack user space tool. I'll send my patches on this early next week when I'm through testing on 2.6.17
thanks
Sam
Re: aggg Re: libnfnetlink_conntrack encapsulation issues
Quoted 10 lines · Amin Azez
* Patrick McHardy wrote, On 27/07/06 15:32:
Quoted 3 lines
One way to add new stuff is to get your patch into the kernel. Other than that its hard, I agree. ifdefs are not a good idea because following members don't have a constant value anymore.
Indeed. Layer7 has been around some time, I guess I will attempt to get
CTA_L7into that file in the official kernel so that those who use the L7 match can get L7 info via contrack /if they want/.
Its not a big deal, but I lean towards not taking such a patch as it is a) only used by an external match and b) wrong anyway in my opinion.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Some matches (like layer7) store state which is output via
/proc/net/ip_conntrack, I also need it as part of conntrack updates. I like receiving a conntrack update when the layer7 is detected, for instance.A match shouldn't do that - what kind of state does it store? Can't you just use your match and combine it with CONNMARK?
Quoted 9 lines
Err... it stores the layer7 pattern that was matched against the packets. So you can recognize a flow as being HTTP or SMTP or DNS etc, by regexing the packets. It only checks the first few packets in each direction of the flow, but having matched, the name of the matching pattern becomes part of the conntrack, and the iptables module can then test this - so you could set a certain connmark based on the ip addresses in combination with some layer7 type; so that HTTP - no matter what the port - could all have a higher priority. This is visible from
/proc/net/ip_conntrack
I actually don't understand the need for the layer7 match at all. The string match with the fsm textsearch algorithm and some clever CONNMARK use should be able to do the same.
Quoted 5 lines
The bigger problem which I guess you answered is, how "new" ctnetlink attributes should be registered and used; how near an extensible framework (which is what I *thought*
libnetlink_conntrackwas for) and how much is just abstraction from the kernel (which it seems *is* whatlibnetlink_conntrackis for).
Its meant for a single purpose - access to the conntrack database. It is extensible enough for this purpose, we can add new attributes in the kernel any time.
Quoted 3 lines
This other problem was how much of
libnetlink_conntrackI am rewriting so that I can vary ever so slightly the conntrack user space tool. I'll send my patches on this early next week when I'm through testing on 2.6.17
I'm also not too happy with the current library. I'm doing some work adding nfnetlink support to libnl, but its far from complete.
Re: aggg Re: libnfnetlink_conntrack encapsulation issues
* Patrick McHardy wrote, On 27/07/06 15:59:
Quoted 7 lines
Quoted 6 lines · Amin Azez
* Patrick McHardy wrote, On 27/07/06 15:32:
Quoted 3 lines
One way to add new stuff is to get your patch into the kernel. Other than that its hard, I agree. ifdefs are not a good idea because following members don't have a constant value anymore.
Quoted 6 lines
Quoted 3 lines
Indeed. Layer7 has been around some time, I guess I will attempt to get
CTA_L7into that file in the official kernel so that those who use the L7 match can get L7 info via contrack /if they want/.Its not a big deal, but I lean towards not taking such a patch as it is a) only used by an external match and b) wrong anyway in my opinion.
I would lean towards not taking it too, but how else to get libnetlink_conntrack to work with arbitrary conntrack attributes? And taking the general case of ct_extend? make_atom is my favoured solution but it might spoil the _XXX_MSG_MAX idea, or we would need multiple atom pools.
Quoted 3 lines
I actually don't understand the need for the layer7 match at all. The string match with the fsm textsearch algorithm and some clever CONNMARK use should be able to do the same.
I heard a layer7 guy saying a similar thing about the string match. I think. :-) It's not like I'm trying to match a particular layer7 protocol, I'm trying to match about a hundred, and managing regex's is easy. Anyway.... I'm not for making everyone like each-others favourite modules; I'm already overusing the mark (IMHO) although some use it more, it really is a boon to have the odd extra conntrack attribute /that I need/
Quoted 3 lines
Its meant for a single purpose - access to the conntrack database. It is extensible enough for this purpose, we can add new attributes in the kernel any time.
thats the bit I'm also trying to do..
I've also extended connmark so that each flow can have its own mark - which sort of helps traffic shaping each direction differently. Naturally of course, I need to get the extra marks from the conntrack database to userspace, along with the original mark. (For compatability there are now 3 marks, the traditional mark, and one set for each direction)
Sam
Re: aggg Re: libnfnetlink_conntrack encapsulation issues
Quoted 11 lines · Amin Azez
* Patrick McHardy wrote, On 27/07/06 15:59:
Quoted 2 lines
Its not a big deal, but I lean towards not taking such a patch as it is a) only used by an external match and b) wrong anyway in my opinion.
I would lean towards not taking it too, but how else to get
libnetlink_conntrackto work with arbitrary conntrack attributes? And taking the general case ofct_extend?make_atomis my favoured solution but it might spoil the_XXX_MSG_MAXidea, or we would need multiple atom pools.
I guess the first question we need to answer is if it has too.
Quoted 5 lines
Quoted 3 lines
I actually don't understand the need for the layer7 match at all. The string match with the fsm textsearch algorithm and some clever CONNMARK use should be able to do the same.
Quoted 7 lines
I heard a layer7 guy saying a similar thing about the string match. I think. :-) It's not like I'm trying to match a particular layer7 protocol, I'm trying to match about a hundred, and managing regex's is easy. Anyway.... I'm not for making everyone like each-others favourite modules; I'm already overusing the mark (IMHO) although some use it more, it really is a boon to have the odd extra conntrack attribute /that I need/
Last time I looked at the layer7 match (long time ago though), it didn't do any optimizations for matching multiple patterns, so I think the string match will perform at least comparable and you will need log2(n) CONNMARK bits. I really hate this idea that every high-level function needs an equivalent in the kernel, just because its harder to use without (with low-level tools).
Quoted 5 lines
I've also extended connmark so that each flow can have its own mark - which sort of helps traffic shaping each direction differently. Naturally of course, I need to get the extra marks from the conntrack database to userspace, along with the original mark. (For compatability there are now 3 marks, the traditional mark, and one set for each direction)
I have been using a patch for a long time that extends the conntrack match by a match on direction, just never made an effort to merge it. You can encode the direction of each packet in the mark independant of connmark. I think this approach is a lot more flexible. I'll take care of adding this (and port matches) sometime if nobody beats me to it.
Pablo Neira Ayuso
maintainerQuoted 54 lines · Amin Azez
I'm reworking some patches from conntrack 0.4.2 to the latest conntrack and I am getting badly bitten by a few problems of encapsulation and over seperation between user and kernel space.
Problem 1:
One of my requirements is to combine
CT_DUMPwithCT_EVENT, so that I get regular events but also an inline dump based on a signal (blah blah blah). Inline (over the same socket) is important as it makes synchronzing the dump with events a little easier.Of course most of this won't belong in
libnetlink_conntrackbut in some conntrack derivative, but the encapsulation ofnfct_handlespoils this.Specifically, I need such behaviours as requesting the conntrack table dump but without the
nfnl_listentacked on the end, for example (simplified fragment):int
nfct_dump_conntrack_table_request(struct nfct_handle *cth, int flags, int family){ int err, msg; struct nfnlhdr req; memset(&req, 0, sizeof(req)); /* This is not important until nfnl_listen we will set it again by then cth->handler = nfct_conntrack_netlink_handler; */ msg = flags; nfnl_fill_hdr(cth->nfnlssh_ct, &req.nlh, 0, family, 0, msg,NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST|NLM_F_DUMP);
err = nfnl_send(cth->nfnlh, &req.nlh); return err; }int
nfct_dump_event_conntrack(struct nfct_handle *cth, int family){ struct sigaction sa; struct sigaction oldint; sa.sa_handler = signal_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; setlinebuf(stdout); sigaction(SIGUSR1, &sa, &oldint); if(nfct_dump_conntrack_table_requestl(cth,IPCTNL_MSG_CT_GET_CTRZERO_EXTRA,family)<0)
Quoted 8 lines
{
exit_error(OTHER_PROBLEM, "Can't request initial dump");
break;
}
/* Break this open later to do our own handler and own callback */
return nfct_event_conntrack(nfct_handle);
}The right thing here is not adding more crap API like this that makes very specific things. The problem with libnetfilter_conntrack is that at the time that I designed it I tried to hide as much netlink details as possible at that was an error.
I just send the patch attached to Patrick, since I can't commit to SVN anymore since my certificate expired. It provides low-level functions for those that want to work with libnfnetlink (or someday libnl) that is what I'm currently doing with conntrackd.
So libnetfilter_conntrack provides the set of specific functions to build netlink messages/attributes and you can use the low level communication layer that you prefer.
Quoted 32 lines
Of course I'd rather do this duplicating as little of
libnetlink_conntrackas possible, but this meanslibnetlink_conntrackneeds to open up its primatives a lttle more. The reason I need my own handler too is because I'm sending back extra tuples including layer7 information (I've submitted patches for this to the layer7 mailing list)Also, as well as
IPCTNL_MSG_CT_GET_CTRZEROinlibnetfilter_conntrack/include/libnetfilter_conntrack/linux_nfnetlink_conntrack.h
I haveIPCTNL_MSG_CT_GET_CTRZERO_EXTRA, which is an alternate message
to pass to the kernel to zero another class of counters. Again, thelibnetlink_conntracklibrary calls don't permit passing individual messages, makinglibnetlink_conntracktightly coupled to a specific kernel and requiring that the kernel capabilities be known tolibnetlink_conntrack- for example, do we need to changelibnetlink_conntrackevery time a new type of data can be dumped? (e.g. layer7?)Problem 2
autogen.sh(mild issue first, not your fault anyway)
Of course my message is defined in my kernel headers which
autogen.shtries to copy accross - except that I am now using the make -o option for the kernel which means that build header files likeautoconf.h,compile.handversion.hare linked to from/lib/modules/uname -r/build but none of the source header files are. For now I can copy the header file by hand but I wonder if anyone has a more general solution to this. I guess that the make process ought to write symlinks to any include dirs to the source.
Quoted 7 lines
However (big problems), when I make autogen copy my version of
nfnetlink_conntrack.h, compiles fail on lack of:CTA_EXPECT_QUEUENRwhich I don't find available in any of the kernel sources I have; so which kernel is being tracked forlibnetfilter_conntrack? The only useful reference google can find is a February chat session which indicates thatlinux_nfnetlink_conntrack.his being kept in SVN so where does the idea ofCTA_EXPECT_QUEUENRcome from?
This is Harald's userspace helper stuff that is pending to be commited, since he's overloaded with work, I propose to remove it temporarily from SVN to avoid breaking things and take it back later once it gets commited.
Quoted 10 lines
In fact I find that despite the assurances in autogen,sh,
linux_nfnetlink_conntrack.hIS being kept in CVN and that the only solution the chatlogs recommend is to revertlinux_nfnetlink_conntrack.hto the supplied one? What?I sometimes wonder if it is time to stop sharing enums like this between kernel and user space and make text labels out of them which applications can resolve into numbers by asking the kernel as they are executed.
enums are OK, the problem is out-of-tree scary things like this layer 7 stuff that makes an insane use of libnetfilter_conntrack.
Signature · 1 line
The dawn of the fourth age of Linux firewalling is coming; a time of great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
Thanks for your help Pablo.
Quoted 3 lines · Pablo Neira Ayuso
enums are OK, the problem is out-of-tree scary things like this layer 7 stuff that makes an insane use of
libnetfilter_conntrack.
ummmm it seems quite normal use, such as any iptables extension that stores per-conntrack information might want to use. I already mentioned the per-flow mark, so that each flow of a conntrack can have its own mark; just like it suseful to get one mark via conntrack, its useful to get the rest too.
I agree, out-of-tree is where it gets scary. I send myself to sleep at night thinking up alternative methods.
Sam
Pablo Neira Ayuso
maintainerQuoted 1 line · Pablo Neira Ayuso
I just send the patch attached to Patrick, since I can't commit to SVN anymore since my certificate expired. It provides low-level functions for those that want to work with libnfnetlink (or someday libnl) that is what I'm currently doing with conntrackd.
Uh, I forgot to attach the patch that I sent to Patrick. It implements a set of functions to build/parse netlink messages for ctnetlink, so you can implement your own functions that do specific things with libnfnetlink and them, I think this is way more flexible.
Signature · 1 line
The dawn of the fourth age of Linux firewalling is coming; a time of great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
libnetfilter_conntrack/linux_nfnetlink_conntrack.h +3 -1
@@ -27,13 +27,15 @@CTA_STATUS ,CTA_PROTOINFO ,CTA_HELP , -CTA_NAT , +CTA_NAT_SRC , +#define CTA_NAT CTA_NAT_SRC /* backwards compatibility */CTA_TIMEOUT ,CTA_MARK ,CTA_COUNTERS_ORIG ,CTA_COUNTERS_REPLY ,CTA_USE ,CTA_ID , +CTA_NAT_DST , __CTA_MAX };#define CTA_MAX (__CTA_MAX - 1)
libnetfilter_conntrack/libnetfilter_conntrack.h +67 -2
103 lines not on this page · raw message
configure.in +1 -1
@@ -4,7 +4,7 @@ AC_CANONICAL_SYSTEM -AM_INIT_AUTOMAKE(libnetfilter_conntrack, 0.0.31) +AM_INIT_AUTOMAKE(libnetfilter_conntrack, 0.0.40) AC_PROG_CC AM_PROG_LIBTOOL
libnetfilter_conntrack.c +371 -116
658 lines not on this page · raw message