Add ARP proto header fields generation via src mac, src ip, dst mac, dst ip & operaion.
By default Ethernet proto will be initialized, and ARP probe request is filled. Signed-off-by: Vadim Kochan <vadi...@gmail.com> --- trafgen_l2.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ trafgen_l2.h | 12 ++++++++++++ 2 files changed, 57 insertions(+) diff --git a/trafgen_l2.c b/trafgen_l2.c index 5d245b8..adee113 100644 --- a/trafgen_l2.c +++ b/trafgen_l2.c @@ -3,10 +3,15 @@ * Subject to the GPL, version 2. */ +#include <net/if_arp.h> +#include <linux/if_ether.h> + #include "built_in.h" #include "trafgen_l2.h" #include "trafgen_proto.h" +#define ETH_BCAST { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } + struct proto_field eth_fields[] = { { .id = ETH_DST_ADDR, .len = 6, }, { .id = ETH_SRC_ADDR, .len = 6, .offset = 6 }, @@ -25,7 +30,47 @@ static struct proto_gen eth_prot = { .header_init = eth_header_init, }; +static struct proto_field arp_fields[] = { + { .id = ARP_HTYPE, .len = 2 }, + { .id = ARP_PTYPE, .len = 2, .offset = 2 }, + { .id = ARP_HLEN, .len = 1, .offset = 4 }, + { .id = ARP_PLEN, .len = 1, .offset = 5 }, + { .id = ARP_OPER, .len = 2, .offset = 6 }, + { .id = ARP_SHA, .len = 6, .offset = 8 }, + { .id = ARP_SPA, .len = 4, .offset = 14 }, + { .id = ARP_THA, .len = 6, .offset = 18 }, + { .id = ARP_TPA, .len = 4, .offset = 24 }, +}; + +static void arp_header_init(struct proto_gen *prot) +{ + uint8_t mac[6] = ETH_BCAST; + + proto_header_init(PROTO_ETH); + + proto_field_set_default_bytes(PROTO_ETH, ETH_DST_ADDR, mac); + proto_field_set_default_be16(PROTO_ETH, ETH_PROTO_ID, ETH_P_ARP); + + proto_fields_add(prot->id, arp_fields, array_size(arp_fields)); + + /* Generate probe request by default */ + proto_field_set_default_be16(prot->id, ARP_HTYPE, ARPHRD_ETHER); + proto_field_set_default_be16(prot->id, ARP_PTYPE, ETH_P_IP); + proto_field_set_default_u8(prot->id, ARP_HLEN, 6); + proto_field_set_default_u8(prot->id, ARP_PLEN, 4); + proto_field_set_default_be16(prot->id, ARP_OPER, ARPOP_REQUEST); + proto_field_set_default_dev_mac(prot->id, ARP_SHA); + proto_field_set_default_dev_ipv4(prot->id, ARP_SPA); + proto_field_set_default_dev_ipv4(prot->id, ARP_TPA); +} + +static struct proto_gen arp_prot = { + .id = PROTO_ARP, + .header_init = arp_header_init, +}; + void protos_l2_init(void) { proto_register(ð_prot); + proto_register(&arp_prot); } diff --git a/trafgen_l2.h b/trafgen_l2.h index 75d3d33..63cef2f 100644 --- a/trafgen_l2.h +++ b/trafgen_l2.h @@ -7,6 +7,18 @@ enum eth_field { ETH_PROTO_ID, }; +enum arp_field { + ARP_HTYPE, + ARP_PTYPE, + ARP_HLEN, + ARP_PLEN, + ARP_OPER, + ARP_SHA, + ARP_SPA, + ARP_THA, + ARP_TPA, +}; + extern void protos_l2_init(void); #endif /* TRAFGEN_L2_I_H */ -- 2.6.3 -- You received this message because you are subscribed to the Google Groups "netsniff-ng" group. To unsubscribe from this group and stop receiving emails from it, send an email to netsniff-ng+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.