src/lib/packet_info.c in trema-0.2.2.1 vs src/lib/packet_info.c in trema-0.2.3

- old
+ new

@@ -1,8 +1,6 @@ /* - * Author: Kazuya Suzuki - * * Copyright (C) 2008-2012 NEC Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, as * published by the Free Software Foundation. @@ -52,18 +50,18 @@ packet_info get_packet_info( const buffer *frame ) { die_if_NULL( frame ); packet_info info; - + if ( frame->user_data != NULL ) { info = *( packet_info * ) frame->user_data; - } + } else { memset( &info, 0, sizeof( info ) ); } - + return info; } static bool @@ -132,10 +130,17 @@ return if_packet_type( frame, NW_IPV4 ); } bool +packet_type_ipv6( const buffer *frame ) { + die_if_NULL( frame ); + return if_packet_type( frame, NW_IPV6 ); +} + + +bool packet_type_lldp( const buffer *frame ) { die_if_NULL( frame ); return if_packet_type( frame, NW_LLDP ); } @@ -160,62 +165,140 @@ return if_packet_type( frame, NW_IPV4 | TP_TCP ); } bool +packet_type_ipv6_tcp( const buffer *frame ) { + die_if_NULL( frame ); + return if_packet_type( frame, NW_IPV6 | TP_TCP ); +} + + +bool packet_type_ipv4_udp( const buffer *frame ) { die_if_NULL( frame ); return if_packet_type( frame, NW_IPV4 | TP_UDP ); } bool +packet_type_ipv6_udp( const buffer *frame ) { + die_if_NULL( frame ); + return if_packet_type( frame, NW_IPV6 | TP_UDP ); +} + + +bool packet_type_ipv4_etherip( const buffer *frame ) { die_if_NULL( frame ); return if_packet_type( frame, NW_IPV4 | TP_ETHERIP ); } static bool +if_arp_opcode( const buffer *frame, const uint32_t opcode ) { + die_if_NULL( frame ); + packet_info packet_info = get_packet_info( frame ); + return ( packet_info.arp_ar_op == opcode ); +} + + +bool +packet_type_arp_request( const buffer *frame ) { + die_if_NULL( frame ); + return ( if_packet_type( frame, NW_ARP ) & + if_arp_opcode( frame, ARP_OP_REQUEST ) ); +} + + +bool +packet_type_arp_reply( const buffer *frame ) { + die_if_NULL( frame ); + return ( if_packet_type( frame, NW_ARP ) & + if_arp_opcode( frame, ARP_OP_REPLY ) ); +} + + +static bool +if_icmpv4_type( const buffer *frame, const uint32_t type ) { + die_if_NULL( frame ); + packet_info packet_info = get_packet_info( frame ); + return ( packet_info.icmpv4_type == type ); +} + + +bool +packet_type_icmpv4_echo_reply( const buffer *frame ) { + die_if_NULL( frame ); + return ( if_packet_type( frame, NW_ICMPV4 ) & + if_icmpv4_type( frame, ICMP_TYPE_ECHOREP ) ); +} + + +bool +packet_type_icmpv4_dst_unreach( const buffer *frame ) { + die_if_NULL( frame ); + return ( if_packet_type( frame, NW_ICMPV4 ) & + if_icmpv4_type( frame, ICMP_TYPE_UNREACH ) ); +} + + +bool +packet_type_icmpv4_redirect( const buffer *frame ) { + die_if_NULL( frame ); + return ( if_packet_type( frame, NW_ICMPV4 ) & + if_icmpv4_type( frame, ICMP_TYPE_REDIRECT ) ); +} + + +bool +packet_type_icmpv4_echo_request( const buffer *frame ) { + die_if_NULL( frame ); + return ( if_packet_type( frame, NW_ICMPV4 ) & + if_icmpv4_type( frame, ICMP_TYPE_ECHOREQ ) ); +} + + +static bool if_igmp_type( const buffer *frame, const uint32_t type ) { die_if_NULL( frame ); packet_info packet_info = get_packet_info( frame ); return ( packet_info.igmp_type == type ); } -bool +bool packet_type_igmp_membership_query( const buffer *frame ) { die_if_NULL( frame ); return ( if_packet_type( frame, NW_IGMP ) & if_igmp_type( frame, IGMP_TYPE_MEMBERSHIP_QUERY ) ); } - -bool + +bool packet_type_igmp_v1_membership_report( const buffer *frame ) { die_if_NULL( frame ); return ( if_packet_type( frame, NW_IGMP ) & if_igmp_type( frame, IGMP_TYPE_V1_MEMBERSHIP_REPORT ) ); } -bool +bool packet_type_igmp_v2_membership_report( const buffer *frame ) { die_if_NULL( frame ); return ( if_packet_type( frame, NW_IGMP ) & if_igmp_type( frame, IGMP_TYPE_V2_MEMBERSHIP_REPORT ) ); } -bool +bool packet_type_igmp_v2_leave_group( const buffer *frame ) { die_if_NULL( frame ); return ( if_packet_type( frame, NW_IGMP ) & if_igmp_type( frame, IGMP_TYPE_V2_LEAVE_GROUP ) ); } -bool +bool packet_type_igmp_v3_membership_report( const buffer *frame ) { die_if_NULL( frame ); return ( if_packet_type( frame, NW_IGMP ) & if_igmp_type( frame, IGMP_TYPE_V3_MEMBERSHIP_REPORT ) ); }