📄 ipsec_ipv6_utilities.c
字号:
}/******************************************************************************* ipsecIpv6GetIpsecOrTransportProtocol - gets the protocol type of ipsec* or the transport protocol. ** This gets the protocol type of the ipsec header or the transport protocol.** NOMANUAL** RETURNS: the protocol type. */int ipsecIpv6GetIpsecOrTransportProtocol ( struct mbuf *m, /* pointer to mbuf */ struct ip6_hdr *ip6 /* ipv6 header */ ) { char *p_nxt_hdr; int nxt_hdr; int ip6_hlen; int ext_hlen = 0; int hdr_traversing_done; if (ip6 == NULL) { ip6 = (struct ip6_hdr *)m->m_data; } ip6_hlen = sizeof (struct ip6_hdr); nxt_hdr = ip6->ip6_nxt; p_nxt_hdr = (char *)(ip6)+ip6_hlen; hdr_traversing_done = 0; while (!hdr_traversing_done) { switch (nxt_hdr) { case IPPROTO_HOPOPTS: case IPPROTO_DSTOPTS: case IPPROTO_ROUTING: /* The length feild in the case of routing ,hop by * hop ,destination extension headers is the header * length in 8-octet units,not counting the first 8 * octets. */ if (m != NULL) { nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); ext_hlen = (8 + ((*(mbufDataPtrAtOffset (m, ip6_hlen + 1))) * 8)); } else { nxt_hdr = *(p_nxt_hdr); ext_hlen = (8 + (*(p_nxt_hdr + 1)) * 8); } break; case IPPROTO_FRAGMENT: /* The Length of the fragment header is 8 bytes */ ext_hlen = 8; if (m != NULL) { nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); } else { nxt_hdr = *(p_nxt_hdr); } break; case IPPROTO_AH: case IPPROTO_ESP: default: hdr_traversing_done = 1; } p_nxt_hdr += ext_hlen; ip6_hlen += ext_hlen; } return nxt_hdr; }/****************************************************************************** * ipsecIpv6EspHdrPtrGet - Gets the pointer to the esp header. * * Gets the pointer to the esp header. * * NOMANUAL * * RETURNS: pointer to the esp header. */UCHAR *ipsecIpv6EspHdrPtrGet ( struct mbuf *m /* pointer to mbuf */ ) { struct ip6_hdr *ip6; char *p_nxt_hdr; int nxt_hdr; int ip6_hlen; int ext_hlen; int hdr_traversing_done; ip6 = (struct ip6_hdr *)m->m_data; ip6_hlen = sizeof (struct ip6_hdr); nxt_hdr = ip6->ip6_nxt; p_nxt_hdr = (char *)(ip6)+ip6_hlen; hdr_traversing_done = 0; while (!hdr_traversing_done) { switch (nxt_hdr) { case IPPROTO_HOPOPTS: case IPPROTO_DSTOPTS: case IPPROTO_ROUTING: /* The length feild in the case of routing ,hop by * hop ,destination extension headers is the header * length in 8-octet units,not counting the first 8 * octets. */ nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); ext_hlen = (8 + ((*(mbufDataPtrAtOffset (m, ip6_hlen + 1))) * 8)); break; case IPPROTO_FRAGMENT: /* The Length of the fragment header is 8 bytes */ ext_hlen = 8; nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); break; case IPPROTO_AH: /* The payoad length field provides the length of the * authentication header in 32 bit words,not counting * the first 8 octets. */ nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); ext_hlen = (8 + ((*(mbufDataPtrAtOffset (m, ip6_hlen + 1))) * 4)); break; case IPPROTO_ESP: return (mbufDataPtrAtOffset (m, ip6_hlen)); default: ext_hlen = 0; hdr_traversing_done = 1; } p_nxt_hdr += ext_hlen; ip6_hlen += ext_hlen; } return (UCHAR *)NULL; }/****************************************************************************** * ipsecIpv6AhHdrPtrGet - Gets the pointer to the ah header. * * Gets the pointer to the ah header. * * NOMANUAL * * RETURNS : pointer to ah header. */UCHAR *ipsecIpv6AhHdrPtrGet ( struct mbuf *m /* pointer to mbuf */ ) { struct ip6_hdr *ip6; char *p_nxt_hdr; int nxt_hdr; int ip6_hlen; int ext_hlen; int hdr_traversing_done; ip6 = (struct ip6_hdr *)m->m_data; ip6_hlen = sizeof (struct ip6_hdr); nxt_hdr = ip6->ip6_nxt; p_nxt_hdr = (char *)(ip6)+ip6_hlen; hdr_traversing_done = 0; while (!hdr_traversing_done) { switch (nxt_hdr) { case IPPROTO_HOPOPTS: case IPPROTO_DSTOPTS: case IPPROTO_ROUTING: /* The length feild in the case of routing ,hop by * hop ,destination extension headers is the header * length in 8-octet units,not counting the first 8 * octets. */ nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); ext_hlen = 8 + (*(mbufDataPtrAtOffset (m, ip6_hlen + 1))) * 8; break; case IPPROTO_FRAGMENT: /* The Length of the fragment header is 8 bytes */ ext_hlen = 8; nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); break; case IPPROTO_AH: return (mbufDataPtrAtOffset (m, ip6_hlen)); case IPPROTO_ESP: default: ext_hlen = 0; hdr_traversing_done = 1; } p_nxt_hdr += ext_hlen; ip6_hlen += ext_hlen; } return (UCHAR *)NULL; }/****************************************************************************** * ipsecIpv6TransportHdrPtrGet - Gets the transport header pointer. * * Gets the transport header pointer. * * NOMANUAL * * RETURNS : byte pointer to the transport header. */UCHAR *ipsecIpv6TransportHdrPtrGet ( struct mbuf *m /* pointer to mbuf */ ) { struct ip6_hdr *ip6; char *p_nxt_hdr; int nxt_hdr; int ip6_hlen; int ext_hlen; int hdr_traversing_done; ip6 = (struct ip6_hdr *)m->m_data; ip6_hlen = sizeof (struct ip6_hdr); nxt_hdr = ip6->ip6_nxt; p_nxt_hdr = (char *)(ip6)+ip6_hlen; hdr_traversing_done = 0; while (!hdr_traversing_done) { switch (nxt_hdr) { case IPPROTO_HOPOPTS: case IPPROTO_DSTOPTS: case IPPROTO_ROUTING: /* The length feild in the case of routing ,hop by * hop ,destination extension headers is the header * length in 8-octet units,not counting the first 8 * octets. */ nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); ext_hlen = (8 + ((*(mbufDataPtrAtOffset (m, ip6_hlen + 1))) * 8)); break; case IPPROTO_FRAGMENT: /* The Length of the fragment header is 8 bytes */ ext_hlen = 8; nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); break; case IPPROTO_AH: case IPPROTO_ESP: default: return (mbufDataPtrAtOffset (m, ip6_hlen)); } p_nxt_hdr += ext_hlen; ip6_hlen += ext_hlen; } /* Should never get here, but compiler will complain */ return NULL; }/****************************************************************************** * ipsecIpv6ExtnsFragmentHdrGet - Gets the pointer to the fragment * header * * Gets the pointer to the fragment header. * * NOMANUAL * * RETURNS : byte pointer to the fragment header. */UCHAR *ipsecIpv6ExtnsFragmentHdrGet ( struct mbuf *m /* pointer to mbuf */ ) { struct ip6_hdr *ip6; UCHAR *p_nxt_hdr; int nxt_hdr; int ip6_hlen; int ext_hlen; ip6 = (struct ip6_hdr *)m->m_data; ip6_hlen = sizeof (struct ip6_hdr); nxt_hdr = ip6->ip6_nxt; p_nxt_hdr = (UCHAR *)(ip6)+ip6_hlen; while (TRUE) { switch (nxt_hdr) { case IPPROTO_HOPOPTS: case IPPROTO_DSTOPTS: case IPPROTO_ROUTING: nxt_hdr = *(mbufDataPtrAtOffset (m, ip6_hlen)); ext_hlen = (8 + ((*(mbufDataPtrAtOffset (m, ip6_hlen + 1))) * 8)); break; case IPPROTO_FRAGMENT: return p_nxt_hdr; case IPPROTO_AH: case IPPROTO_ESP: case TRANSPORT_PROTO_TCP: case TRANSPORT_PROTO_UDP: case IPPROTO_NONE: default: return NULL; } p_nxt_hdr += ext_hlen; ip6_hlen += ext_hlen; } /* Code is not expected to reach here */ } /*****************************************************************************/#endif /* STACK_NAME == STACK_NAME_V4_V6 && defined (INET6) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -