Add IP proto utils function

This commit is contained in:
luwenpeng
2024-06-02 00:36:50 +08:00
parent 18fe1e2e41
commit eb1056b4f9
5 changed files with 119 additions and 79 deletions

View File

@@ -34,17 +34,16 @@
(tag), (next_proto), eth_proto_to_str(next_proto)); \
}
#define PACKET_LOG_UNSUPPORT_IPPROTO(tag, next_proto) \
{ \
PACKET_LOG_WARN("%s: unsupport next ip proto %d: %s", \
(tag), (next_proto), ipproto_to_str(next_proto)); \
#define PACKET_LOG_UNSUPPORT_IPPROTO(tag, next_proto) \
{ \
PACKET_LOG_WARN("%s: unsupport next ip proto %d: %s", \
(tag), (next_proto), ip_proto_to_str(next_proto)); \
}
/******************************************************************************
* Static API
******************************************************************************/
static const char *ipproto_to_str(uint16_t proto);
static inline const char *ldbc_method_to_str(enum ldbc_method method);
static inline const char *layer_type_to_str(enum layer_type type);
@@ -91,71 +90,6 @@ static inline const char *parse_l4(struct packet *pkt, uint8_t next_proto, const
* Private API -- Utils
******************************************************************************/
static const char *ipproto_to_str(uint16_t proto)
{
switch (proto)
{
case IPPROTO_IP:
return "IP";
case IPPROTO_ICMP:
return "ICMP";
case IPPROTO_IGMP:
return "IGMP";
case IPPROTO_IPIP:
return "IPIP";
case IPPROTO_TCP:
return "TCP";
case IPPROTO_EGP:
return "EGP";
case IPPROTO_PUP:
return "PUP";
case IPPROTO_UDP:
return "UDP";
case IPPROTO_IDP:
return "IDP";
case IPPROTO_TP:
return "TP";
case IPPROTO_DCCP:
return "DCCP";
case IPPROTO_IPV6:
return "IPV6";
case IPPROTO_ROUTING:
return "ROUTING";
case IPPROTO_FRAGMENT:
return "FRAGMENT";
case IPPROTO_RSVP:
return "RSVP";
case IPPROTO_GRE:
return "GRE";
case IPPROTO_ESP:
return "ESP";
case IPPROTO_AH:
return "AH";
case IPPROTO_ICMPV6:
return "ICMPV6";
case IPPROTO_NONE:
return "NONE";
case IPPROTO_DSTOPTS:
return "DSTOPTS";
case IPPROTO_MTP:
return "MTP";
case IPPROTO_ENCAP:
return "ENCAP";
case IPPROTO_PIM:
return "PIM";
case IPPROTO_COMP:
return "COMP";
case IPPROTO_SCTP:
return "SCTP";
case IPPROTO_UDPLITE:
return "UDPLITE";
case IPPROTO_RAW:
return "RAW";
default:
return "UNKNOWN";
}
}
static inline const char *ldbc_method_to_str(enum ldbc_method method)
{
switch (method)