diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-06-12 18:35:11 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-06-12 18:35:11 +0200 |
commit | d9c0564db6b3f3ecb196508458a91b03d45fadb2 (patch) | |
tree | 327dec2eab601abe26522c267bdff23b1605dfc5 /src/parse.c | |
parent | 8fc9066ee62d17cdb76bc064c945da3bb0d2e2a3 (diff) | |
download | conntrack-tools-d9c0564db6b3f3ecb196508458a91b03d45fadb2.tar.gz conntrack-tools-d9c0564db6b3f3ecb196508458a91b03d45fadb2.zip |
build: use TLV format for SCTP/DCCP protocol information
In 400ae54438c4b85126f9fab0ae1dc067823b70f7, we added the SCTP
support by means of a structure that was encapsulated in an
TLV attribute. However, this structure didn't handle alignment
and endianess issues appropriately. Similar problem was
introduced in b808645ec71b7cc22cf5106b3d79625d07e6077c along
with the DCCP support.
This patch moves every field of this structure to independent
attributes. I decided not to use nesting to make building and
parsing more simple.
Using TLV is a good idea, specially for DCCP and SCTP that are
under development and that may include new fields and obsolete
them in the future.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parse.c')
-rw-r--r-- | src/parse.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/parse.c b/src/parse.c index 100177b..1bdfcc7 100644 --- a/src/parse.c +++ b/src/parse.c @@ -29,8 +29,6 @@ static void parse_u16(struct nf_conntrack *ct, int attr, void *data); static void parse_u32(struct nf_conntrack *ct, int attr, void *data); static void parse_group(struct nf_conntrack *ct, int attr, void *data); static void parse_nat_seq_adj(struct nf_conntrack *ct, int attr, void *data); -static void parse_sctp(struct nf_conntrack *ct, int attr, void *data); -static void parse_dccp(struct nf_conntrack *ct, int attr, void *data); struct parser { void (*parse)(struct nf_conntrack *ct, int attr, void *data); @@ -59,7 +57,7 @@ static struct parser h[NTA_MAX] = { .attr = ATTR_L4PROTO, .size = NTA_SIZE(sizeof(uint8_t)), }, - [NTA_STATE_TCP] = { + [NTA_TCP_STATE] = { .parse = parse_u8, .attr = ATTR_TCP_STATE, .size = NTA_SIZE(sizeof(uint8_t)), @@ -123,13 +121,30 @@ static struct parser h[NTA_MAX] = { .parse = parse_nat_seq_adj, .size = NTA_SIZE(sizeof(struct nta_attr_natseqadj)), }, - [NTA_STATE_SCTP] = { - .parse = parse_sctp, - .size = NTA_SIZE(sizeof(struct nta_attr_sctp)), + [NTA_SCTP_STATE] = { + .parse = parse_u8, + .attr = ATTR_SCTP_STATE, + .size = NTA_SIZE(sizeof(uint8_t)), }, - [NTA_STATE_DCCP] = { - .parse = parse_dccp, - .size = NTA_SIZE(sizeof(struct nta_attr_dccp)), + [NTA_SCTP_VTAG_ORIG] = { + .parse = parse_u32, + .attr = ATTR_SCTP_VTAG_ORIG, + .size = NTA_SIZE(sizeof(uint32_t)), + }, + [NTA_SCTP_VTAG_REPL] = { + .parse = parse_u32, + .attr = ATTR_SCTP_VTAG_REPL, + .size = NTA_SIZE(sizeof(uint32_t)), + }, + [NTA_DCCP_STATE] = { + .parse = parse_u8, + .attr = ATTR_DCCP_STATE, + .size = NTA_SIZE(sizeof(uint8_t)), + }, + [NTA_DCCP_ROLE] = { + .parse = parse_u8, + .attr = ATTR_DCCP_ROLE, + .size = NTA_SIZE(sizeof(uint8_t)), }, }; @@ -178,23 +193,6 @@ parse_nat_seq_adj(struct nf_conntrack *ct, int attr, void *data) ntohl(this->orig_seq_correction_pos)); } -static void -parse_sctp(struct nf_conntrack *ct, int attr, void *data) -{ - struct nta_attr_sctp *this = data; - nfct_set_attr_u8(ct, ATTR_SCTP_STATE, this->state); - nfct_set_attr_u32(ct, ATTR_SCTP_VTAG_ORIG, ntohl(this->vtag_orig)); - nfct_set_attr_u32(ct, ATTR_SCTP_VTAG_REPL, ntohl(this->vtag_repl)); -} - -static void -parse_dccp(struct nf_conntrack *ct, int attr, void *data) -{ - struct nta_attr_dccp *this = data; - nfct_set_attr_u8(ct, ATTR_DCCP_STATE, this->state); - nfct_set_attr_u8(ct, ATTR_DCCP_ROLE, this->role); -} - int parse_payload(struct nf_conntrack *ct, struct nethdr *net, size_t remain) { int len; |