diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2011-11-20 13:23:15 +0000 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2012-03-05 13:32:22 -0800 |
commit | 29e72f7ad1ecf82a8fb5c33786dfe6b4cad4ac9b (patch) | |
tree | cf25322e3aee3aa86e1edabb25f5f1bb33bae8b1 /libnet/include | |
parent | 508502b8eef27ca194e57f6144d9ad43809154a9 (diff) | |
download | libnet-29e72f7ad1ecf82a8fb5c33786dfe6b4cad4ac9b.tar.gz |
Reworked icmpv6 patch to parallel the form of icmpv4 support.
Use same calling sequences, identifier names modelled on
<netinet/icmp6.h>, etc.
Diffstat (limited to 'libnet/include')
-rw-r--r-- | libnet/include/libnet/libnet-functions.h | 89 | ||||
-rw-r--r-- | libnet/include/libnet/libnet-headers.h | 129 | ||||
-rw-r--r-- | libnet/include/libnet/libnet-structures.h | 10 |
3 files changed, 155 insertions, 73 deletions
diff --git a/libnet/include/libnet/libnet-functions.h b/libnet/include/libnet/libnet-functions.h index f2d4226..4d9c057 100644 --- a/libnet/include/libnet/libnet-functions.h +++ b/libnet/include/libnet/libnet-functions.h @@ -777,28 +777,29 @@ libnet_build_icmpv4_timestamp(uint8_t type, uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t otime, uint32_t rtime, uint32_t ttime, const uint8_t* payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag); -/* - * Builds an ICMPv6 header - * @param type type of ICMPv6 packet - * @param code code of ICMP packet - * @param sum checksum (0 for libnet to autofill) +/** + * Builds an IP version 6 RFC 4443 Internet Control Message Protocol (ICMP) + * echo or echo reply header. + * @param type type of ICMP packet (should be ICMP6_ECHO_REQUEST or ICMP6_ECHO_REPLY) + * @param code code of ICMP packet (should be zero) + * @param id echo id number + * @param seq echo sequence number * @param payload optional payload or NULL * @param payload_s payload length or 0 * @param l pointer to a libnet context * @param ptag protocol tag to modify an existing header, 0 to build a new one - * See definitions of types and codes (ICMP6_*) in struct libnet_icmpv6_hdr. * @return protocol tag value on success, -1 on error */ -libnet_ptag_t libnet_build_icmpv6(uint8_t type, uint8_t code, uint16_t sum, - uint8_t* payload, uint32_t payload_s, - libnet_t* l, libnet_ptag_t ptag); +libnet_ptag_t libnet_build_icmpv6_echo(uint8_t type, uint8_t code, uint16_t + sum, uint16_t id, uint16_t seq, uint8_t *payload, uint32_t payload_s, + libnet_t *l, libnet_ptag_t ptag); /** * Builds an IP version 6 RFC 4443 Internet Control Message Protocol (ICMP) * unreachable header. The IP header that caused the error message should be * built by a previous call to libnet_build_ipv6(). - * @param type type of ICMP packet (should be ICMP6_UNREACH) - * @param code code of ICMP packet (should be one of the 5 unreachable codes) + * @param type type of ICMP packet (should be ICMP6_DST_UNREACH) + * @param code code of ICMP packet (should be one of the 5 ICMP6_DST_UNREACH_* codes) * @param sum checksum (0 for libnet to autofill) * @param payload optional payload or NULL * @param payload_s payload length or 0 @@ -811,57 +812,53 @@ libnet_build_icmpv6_unreach(uint8_t type, uint8_t code, uint16_t sum, uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag); /** - * Builds ICMPv6 echo header - * @param id echo id number - * @param seq echo sequence number - * @param data optional payload or NULL - * @param datalen payload length or 0 - * @param l pointer to a libnet context - * @param ptag protocol tag to modify an existing header, 0 to build a new one - * @return protocol tag value on success, -1 on error - */ -libnet_ptag_t libnet_build_icmpv6_echo(uint16_t id, uint16_t seq, - uint8_t *data, uint32_t datalen, - libnet_t *l, libnet_ptag_t ptag); - -/** - * Builds ICMPv6 Neighbor Solicitation header - * @param tgt target ipv6 address + * Builds an IP version 6 RFC 2461 Internet Control Message Protocol (ICMP) + * NDP neighbour solicitation header. Could be used with + * libnet_build_icmpv6_ndp_opt() and ICMPV6_NDP_OPT_SLLA. + * @param type type of ICMP packet (should be ND_NEIGHBOR_SOLICIT) + * @param code code of ICMP packet (should be zero) + * @param sum checksum (0 for libnet to autofill) + * @param target target ipv6 address + * @param payload optional payload or NULL + * @param payload_s payload length or 0 * @param l pointer to a libnet context * @param ptag protocol tag to modify an existing header, 0 to build a new one * @return protocol tag value on success, -1 on error */ - - -libnet_ptag_t libnet_build_icmpv6_nsol(struct libnet_in6_addr tgt, - libnet_t* l, libnet_ptag_t ptag); +libnet_ptag_t libnet_build_icmpv6_ndp_nsol(uint8_t type, uint8_t code, + uint16_t sum, struct libnet_in6_addr target, uint8_t *payload, uint32_t + payload_s, libnet_t* l, libnet_ptag_t ptag); /** - * Builds ICMPv6 Neighbor Advertisement header - * @param flags neighbor advertisement flags - * @param tgt target ipv6 address + * Builds an IP version 6 RFC 2461 Internet Control Message Protocol (ICMP) + * NDP neighbour advertisement header. Could be used with + * libnet_build_icmpv6_ndp_opt() and ND_OPT_TARGET_LINKADDR. + * @param type type of ICMP packet (should be ND_NEIGHBOR_ADVERT) + * @param code code of ICMP packet (should be zero) + * @param sum checksum (0 for libnet to autofill) + * @param flags should be a bitwise or of any applicable ND_NA_FLAG_* flags + * @param target target ipv6 address + * @param payload optional payload or NULL + * @param payload_s payload length or 0 * @param l pointer to a libnet context * @param ptag protocol tag to modify an existing header, 0 to build a new one * @return protocol tag value on success, -1 on error */ -libnet_ptag_t libnet_build_icmpv6_nadv(uint32_t flags, - struct libnet_in6_addr tgt, - libnet_t* l, libnet_ptag_t ptag); +libnet_ptag_t libnet_build_icmpv6_ndp_nadv(uint8_t type, uint8_t code, + uint16_t sum, uint32_t flags, struct libnet_in6_addr target, uint8_t + *payload, uint32_t payload_s, libnet_t* l, libnet_ptag_t ptag); /** - * Builds ICMPv6 NDP link-layer address option - * @param type address type (ICMPV6_NDPOPT_SLLA for source, ICMPV6_NDPOPT_TLLA for target) - * @param len addess length in 8-byte chunks FIXME builder should calculate len if it is zero - * @param mac hardware address - * @param maclen hardware address length FIXME builder doesn't pad to 8-byte boundaries, if caller doesn't, option is invalid + * Builds ICMPv6 NDP options. + * @param type one of ND_OPT_* types + * @param option option data + * @param option_s size of option data (will be padded out to an 8-byte boundary) * @param l pointer to a libnet context * @param ptag protocol tag to modify an existing header, 0 to build a new one * @return protocol tag value on success, -1 on error - */ -libnet_ptag_t libnet_build_icmpv6_ndp_lla(uint8_t type, uint8_t len, - uint8_t* mac, uint32_t maclen, - libnet_t* l, libnet_ptag_t ptag); +libnet_ptag_t libnet_build_icmpv6_ndp_opt(uint8_t type, uint8_t* option, + uint32_t option_s, libnet_t* l, libnet_ptag_t ptag); /** * Builds an RFC 1112 Internet Group Memebership Protocol (IGMP) header. diff --git a/libnet/include/libnet/libnet-headers.h b/libnet/include/libnet/libnet-headers.h index 2e01541..3b908d7 100644 --- a/libnet/include/libnet/libnet-headers.h +++ b/libnet/include/libnet/libnet-headers.h @@ -63,11 +63,9 @@ #define LIBNET_ICMPV4_TIMXCEED_H 0x08 /**< ICMP_TIMXCEED header: 8 bytes */ #define LIBNET_ICMPV4_REDIRECT_H 0x08 /**< ICMP_REDIRECT header: 8 bytes */ #define LIBNET_ICMPV4_TS_H 0x14 /**< ICMP_TIMESTAMP headr:20 bytes */ -#define LIBNET_ICMPV6_H 0x04 /**< ICMP6 header base: 4 bytes */ +#define LIBNET_ICMPV6_COMMON_H 0x04 /**< ICMP6 header base: 4 bytes */ +#define LIBNET_ICMPV6_H 0x08 /**< ICMP6 header base: 8 bytes (unused, for backwards compatibility) */ #define LIBNET_ICMPV6_UNREACH_H 0x08 /**< ICMP6 unreach base: 8 bytes */ -#define LIBNET_ICMPV6_ECHO_H 0x04 /**< ICMP6 echo header: 4 bytes */ -#define LIBNET_ICMPV6_NDP_NSA_H 0x14 /**< ICMP6 NDP header: 20 bytes */ -#define LIBNET_ICMPV6_NDP_OPT_H 0x02 /**< ICMP6 ndp options: 2 bytes */ #define LIBNET_IGMP_H 0x08 /**< IGMP header: 8 bytes */ #define LIBNET_IPV4_H 0x14 /**< IPv4 header: 20 bytes */ #define LIBNET_IPV6_H 0x28 /**< IPv6 header: 40 bytes */ @@ -822,52 +820,139 @@ struct libnet_ipv6_hbhopts_hdr * Internet Control Message Protocol v6 * Base header size: 4 bytes */ -#define IPPROTO_ICMP6 0x3a +#ifndef IPPROTO_ICMPV6 +#define IPPROTO_ICMPV6 58 +#endif struct libnet_icmpv6_hdr { uint8_t icmp_type; /* ICMP type */ +/* Don't define if <netinet/icmp6.h> has defined them. */ +#ifndef ICMP6_ECHO_REQUEST +#define ICMP6_ECHO_REQUEST 128 +#endif +#ifndef ICMP6_ECHO_REPLY +#define ICMP6_ECHO_REPLY 129 +#endif +#ifndef ICMP6_DST_UNREACH +#define ICMP6_DST_UNREACH 1 +#endif +#ifndef ICMP6_PACKET_TOO_BIG +#define ICMP6_PACKET_TOO_BIG 2 +#endif +#ifndef ICMP6_TIME_EXCEEDED +#define ICMP6_TIME_EXCEEDED 3 +#endif +#ifndef ICMP6_PARAM_PROB +#define ICMP6_PARAM_PROB 4 +#endif + +#ifndef ND_ROUTER_SOLICIT +#define ND_ROUTER_SOLICIT 133 +#endif +#ifndef ND_ROUTER_ADVERT +#define ND_ROUTER_ADVERT 134 +#endif +#ifndef ND_NEIGHBOR_SOLICIT +#define ND_NEIGHBOR_SOLICIT 135 +#endif +#ifndef ND_NEIGHBOR_ADVERT +#define ND_NEIGHBOR_ADVERT 136 +#endif + + uint8_t icmp_code; /* ICMP code */ +#ifndef ICMP6_DST_UNREACH_NOROUTE +#define ICMP6_DST_UNREACH_NOROUTE 0 +#endif +#ifndef ICMP6_DST_UNREACH_ADMIN +#define ICMP6_DST_UNREACH_ADMIN 1 +#endif +#ifndef ICMP6_DST_UNREACH_BEYONDSCOPE +#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 +#endif +#ifndef ICMP6_DST_UNREACH_ADDR +#define ICMP6_DST_UNREACH_ADDR 3 +#endif +#ifndef ICMP6_DST_UNREACH_NOPORT +#define ICMP6_DST_UNREACH_NOPORT 4 +#endif + uint16_t icmp_sum; /* ICMP Checksum */ + + /* This is confusing: id/seq are used only for echo req/reply, but must + * exist in struct for backwards compatibility. */ + uint16_t id; /* ICMP id (unused, for backwards compatibility) */ + uint16_t seq; /* ICMP sequence number (unused, for backwards compatibility) */ + + /* Non-standard names, for libnet backwards compatibility, don't use. */ + /* ipproto: */ +#define IPPROTO_ICMP6 58 + /* types: */ #define ICMP6_ECHO 128 #define ICMP6_ECHOREPLY 129 -#define ICMP6_ROUTERSOL 133 -#define ICMP6_ROUTERADV 134 -#define ICMP6_NEIGHSOL 135 -#define ICMP6_NEIGHADV 136 - #define ICMP6_UNREACH 1 #define ICMP6_PKTTOOBIG 2 #define ICMP6_TIMXCEED 3 #define ICMP6_PARAMPROB 4 - uint8_t icmp_code; /* ICMP code */ + /* codes: */ #define ICMP6_NOROUTE 0 #define ICMP6_ADM_PROHIBITED 1 #define ICMP6_NOT_NEIGHBOUR 2 #define ICMP6_ADDR_UNREACH 3 #define ICMP6_PORT_UNREACH 4 - uint16_t icmp_sum; /* ICMP Checksum */ }; /* All of this stuff follows base ICMPv6 header */ +struct libnet_icmpv6_unreach { + uint32_t unused; +}; + struct libnet_icmpv6_echo { uint16_t id; uint16_t seq; }; -struct libnet_icmpv6_ndp_nsa { +struct libnet_icmpv6_ndp_nsol { + uint32_t reserved; + struct libnet_in6_addr target_addr; +}; + +struct libnet_icmpv6_ndp_nadv { uint32_t flags; -#define NDP_FL_ROUTER (1 << 31) -#define NDP_FL_SOLICITED (1 << 30) -#define NDP_FL_OVERRIDE (1 << 29) - struct libnet_in6_addr tgt_addr; +#ifndef ND_NA_FLAG_ROUTER +#define ND_NA_FLAG_ROUTER 0x80000000 +#endif +#ifndef ND_NA_FLAG_SOLICITED +#define ND_NA_FLAG_SOLICITED 0x40000000 +#endif +#ifndef ND_NA_FLAG_OVERRIDE +#define ND_NA_FLAG_OVERRIDE 0x20000000 +#endif + struct libnet_in6_addr target_addr; }; struct libnet_icmpv6_ndp_opt { uint8_t type; -#define ICMPV6_NDPOPT_SLLA 1 -#define ICMPV6_NDPOPT_TLLA 2 -#define ICMPV6_NDPOPT_PREFIX 3 -#define ICMPV6_NDPOPT_REDHDR 4 -#define ICMPV6_NDPOPT_MTU 5 +#ifndef ND_OPT_SOURCE_LINKADDR +#define ND_OPT_SOURCE_LINKADDR 1 +#endif +#ifndef ND_OPT_TARGET_LINKADDR +#define ND_OPT_TARGET_LINKADDR 2 +#endif +#ifndef ND_OPT_PREFIX_INFORMATION +#define ND_OPT_PREFIX_INFORMATION 3 +#endif +#ifndef ND_OPT_REDIRECTED_HEADER +#define ND_OPT_REDIRECTED_HEADER 4 +#endif +#ifndef ND_OPT_MTU +#define ND_OPT_MTU 5 +#endif +#ifndef ND_OPT_RTR_ADV_INTERVAL +#define ND_OPT_RTR_ADV_INTERVAL 7 +#endif +#ifndef ND_OPT_HOME_AGENT_INFO +#define ND_OPT_HOME_AGENT_INFO 8 +#endif uint8_t len; }; diff --git a/libnet/include/libnet/libnet-structures.h b/libnet/include/libnet/libnet-structures.h index 831999e..bd7b55b 100644 --- a/libnet/include/libnet/libnet-structures.h +++ b/libnet/include/libnet/libnet-structures.h @@ -158,12 +158,12 @@ struct libnet_protocol_block #define LIBNET_PBLOCK_IPV6_HBHOPTS_H 0x3e /* IPv6 hop/hop opts header */ #define LIBNET_PBLOCK_SEBEK_H 0x3f /* Sebek header */ #define LIBNET_PBLOCK_HSRP_H 0x40 /* HSRP header */ -#define LIBNET_PBLOCK_ICMPV6_H 0x41 /* ICMPv6 header */ -#define LIBNET_PBLOCK_ICMPV6_UNREACH_H 0x42 /* ICMPv6 unreach header */ -#define LIBNET_PBLOCK_ICMPV6_NDNSOL_H 0x43 /* ICMPv6 neighbor solicitation header */ -#define LIBNET_PBLOCK_ICMPV6_NDNADV_H 0x44 /* ICMPv6 neighbor adv header */ -#define LIBNET_PBLOCK_ICMPV6_NDPOPT_H 0x45 /* ICMPv6 NDP option */ +#define LIBNET_PBLOCK_ICMPV6_H 0x41 /* ICMPv6 header (unused) */ #define LIBNET_PBLOCK_ICMPV6_ECHO_H 0x46 /* ICMPv6 echo header */ +#define LIBNET_PBLOCK_ICMPV6_UNREACH_H 0x42 /* ICMPv6 unreach header */ +#define LIBNET_PBLOCK_ICMPV6_NDP_NSOL_H 0x43 /* ICMPv6 NDP neighbor solicitation header */ +#define LIBNET_PBLOCK_ICMPV6_NDP_NADV_H 0x44 /* ICMPv6 NDP neighbor advertisement header */ +#define LIBNET_PBLOCK_ICMPV6_NDP_OPT_H 0x45 /* ICMPv6 NDP option */ uint8_t flags; /* control flags */ #define LIBNET_PBLOCK_DO_CHECKSUM 0x01 /* needs a checksum */ |