1 #ifndef __ICMP_H_ 2 #define __ICMP_H_ 3 4 #include "mos_api.h" 5 /*----------------------------------------------------------------------------*/ 6 struct icmphdr { 7 uint8_t icmp_type; 8 uint8_t icmp_code; 9 uint16_t icmp_checksum; 10 union { 11 struct { 12 uint16_t icmp_id; 13 uint16_t icmp_sequence; 14 } echo; // ECHO | ECHOREPLY 15 struct { 16 uint16_t unused; 17 uint16_t nhop_mtu; 18 } dest; // DEST_UNREACH 19 } un; 20 }; 21 /*----------------------------------------------------------------------------*/ 22 /* getters and setters for ICMP fields */ 23 #define ICMP_ECHO_GET_ID(icmph) (icmph->un.echo.icmp_id) 24 #define ICMP_ECHO_GET_SEQ(icmph) (icmph->un.echo.icmp_sequence) 25 #define ICMP_DEST_UNREACH_GET_MTU(icmph) (icmph->un.dest.nhop_mtu) 26 27 #define ICMP_ECHO_SET_ID(icmph, id) (icmph->un.echo.icmp_id = id) 28 #define ICMP_ECHO_SET_SEQ(icmph, seq) (icmph->un.echo.icmp_sequence = seq) 29 /*----------------------------------------------------------------------------*/ 30 void 31 RequestICMP(mtcp_manager_t mtcp, struct pkt_ctx *pctx, uint32_t saddr, uint32_t daddr, 32 uint16_t icmp_id, uint16_t icmp_seq, 33 uint8_t *icmpd, uint16_t len); 34 35 int 36 ProcessICMPPacket(mtcp_manager_t mtcp, struct pkt_ctx *pctx); 37 38 /* ICMP types */ 39 #define ICMP_ECHOREPLY 0 /* Echo Reply */ 40 #define ICMP_DEST_UNREACH 3 /* Destination Unreachable */ 41 #define ICMP_SOURCE_QUENCH 4 /* Source Quench */ 42 #define ICMP_REDIRECT 5 /* Redirect (change route) */ 43 #define ICMP_ECHO 8 /* Echo Request */ 44 #define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */ 45 #define ICMP_PARAMETERPROB 12 /* Parameter Problem */ 46 #define ICMP_TIMESTAMP 13 /* Timestamp Request */ 47 #define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */ 48 #define ICMP_INFO_REQUEST 15 /* Information Request */ 49 #define ICMP_INFO_REPLY 16 /* Information Reply */ 50 #define ICMP_ADDRESS 17 /* Address Mask Request */ 51 #define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */ 52 /*----------------------------------------------------------------------------*/ 53 #endif /* __ICMP_H_ */ 54