summaryrefslogtreecommitdiff
path: root/trafgen_l3.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-08-12 09:46:59 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-08-12 09:46:59 +0200
commitee3f53306b1ceb5235ac587c2e0a605c13922d78 (patch)
tree091b354a9a5722498b56b22fc7572415803d84be /trafgen_l3.c
parent355bbe1b1e7fe1b0ab07fe2de8cb6e64418d51e0 (diff)
trafgen: proto: Split static protocol definition out of struct proto_hdr
Currently struct proto_hdr is used twofold: 1) Statically define protocol behavior, i.e. all the *_hdr definitions in trafgen_l{2,3,4}.c which map a protocol id/layer to a set of callback functions. 2) For each packet created at parse time the struct is memcpy()'ed (including all the static information from 1) and then used to store dynamic information at parse/run time. Thus, struct proto_hdr members such as the proto id, layer and the pointers callback functions get copied for each created packet (in addition to the other fields which get changed during parsing). Also, static/dynamic information get mixed and we e.g. can't make the protocol definitions const to ensure they'll not get changed by mistake. Rather than copying the struct proto_hdr for every packet, clearly separate the two purposes defined above by splitting struct proto_hdr into two structs: 1) struct proto_ops for the static (const) protocol behavior definition 2) struct proto_hdr (reduced) for dynamic information struct proto_hdr keeps a pointer to the corresponding proto_ops instance and uses it to execute the corresponding callbacks. Reference: https://groups.google.com/forum/#!msg/netsniff-ng/20RvwJdh50Y/eMkbmKSaBgAJ Acked-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_l3.c')
-rw-r--r--trafgen_l3.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/trafgen_l3.c b/trafgen_l3.c
index 1cdd041..2eabef1 100644
--- a/trafgen_l3.c
+++ b/trafgen_l3.c
@@ -86,7 +86,7 @@ static void ipv4_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
proto_field_set_default_u8(hdr, IP4_PROTO, ip_proto);
}
-static struct proto_hdr ipv4_hdr = {
+static const struct proto_ops ipv4_proto_ops = {
.id = PROTO_IP4,
.layer = PROTO_L3,
.header_init = ipv4_header_init,
@@ -146,7 +146,7 @@ static void ipv6_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
proto_field_set_default_u8(hdr, IP6_NEXT_HDR, ip_proto);
}
-static struct proto_hdr ipv6_hdr = {
+static const struct proto_ops ipv6_proto_ops = {
.id = PROTO_IP6,
.layer = PROTO_L3,
.header_init = ipv6_header_init,
@@ -156,6 +156,6 @@ static struct proto_hdr ipv6_hdr = {
void protos_l3_init(void)
{
- proto_header_register(&ipv4_hdr);
- proto_header_register(&ipv6_hdr);
+ proto_ops_register(&ipv4_proto_ops);
+ proto_ops_register(&ipv6_proto_ops);
}