OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [tags/] [linux-2.6/] [linux-2.6.24_or32_unified_v2.3/] [net/] [ipv6/] [exthdrs_core.c] - Diff between revs 3 and 8

Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 8
/*
/*
 * IPv6 library code, needed by static components when full IPv6 support is
 * IPv6 library code, needed by static components when full IPv6 support is
 * not configured or static.
 * not configured or static.
 */
 */
#include <net/ipv6.h>
#include <net/ipv6.h>
 
 
/*
/*
 * find out if nexthdr is a well-known extension header or a protocol
 * find out if nexthdr is a well-known extension header or a protocol
 */
 */
 
 
int ipv6_ext_hdr(u8 nexthdr)
int ipv6_ext_hdr(u8 nexthdr)
{
{
        /*
        /*
         * find out if nexthdr is an extension header or a protocol
         * find out if nexthdr is an extension header or a protocol
         */
         */
        return ( (nexthdr == NEXTHDR_HOP)       ||
        return ( (nexthdr == NEXTHDR_HOP)       ||
                 (nexthdr == NEXTHDR_ROUTING)   ||
                 (nexthdr == NEXTHDR_ROUTING)   ||
                 (nexthdr == NEXTHDR_FRAGMENT)  ||
                 (nexthdr == NEXTHDR_FRAGMENT)  ||
                 (nexthdr == NEXTHDR_AUTH)      ||
                 (nexthdr == NEXTHDR_AUTH)      ||
                 (nexthdr == NEXTHDR_NONE)      ||
                 (nexthdr == NEXTHDR_NONE)      ||
                 (nexthdr == NEXTHDR_DEST) );
                 (nexthdr == NEXTHDR_DEST) );
}
}
 
 
/*
/*
 * Skip any extension headers. This is used by the ICMP module.
 * Skip any extension headers. This is used by the ICMP module.
 *
 *
 * Note that strictly speaking this conflicts with RFC 2460 4.0:
 * Note that strictly speaking this conflicts with RFC 2460 4.0:
 * ...The contents and semantics of each extension header determine whether
 * ...The contents and semantics of each extension header determine whether
 * or not to proceed to the next header.  Therefore, extension headers must
 * or not to proceed to the next header.  Therefore, extension headers must
 * be processed strictly in the order they appear in the packet; a
 * be processed strictly in the order they appear in the packet; a
 * receiver must not, for example, scan through a packet looking for a
 * receiver must not, for example, scan through a packet looking for a
 * particular kind of extension header and process that header prior to
 * particular kind of extension header and process that header prior to
 * processing all preceding ones.
 * processing all preceding ones.
 *
 *
 * We do exactly this. This is a protocol bug. We can't decide after a
 * We do exactly this. This is a protocol bug. We can't decide after a
 * seeing an unknown discard-with-error flavour TLV option if it's a
 * seeing an unknown discard-with-error flavour TLV option if it's a
 * ICMP error message or not (errors should never be send in reply to
 * ICMP error message or not (errors should never be send in reply to
 * ICMP error messages).
 * ICMP error messages).
 *
 *
 * But I see no other way to do this. This might need to be reexamined
 * But I see no other way to do this. This might need to be reexamined
 * when Linux implements ESP (and maybe AUTH) headers.
 * when Linux implements ESP (and maybe AUTH) headers.
 * --AK
 * --AK
 *
 *
 * This function parses (probably truncated) exthdr set "hdr".
 * This function parses (probably truncated) exthdr set "hdr".
 * "nexthdrp" initially points to some place,
 * "nexthdrp" initially points to some place,
 * where type of the first header can be found.
 * where type of the first header can be found.
 *
 *
 * It skips all well-known exthdrs, and returns pointer to the start
 * It skips all well-known exthdrs, and returns pointer to the start
 * of unparsable area i.e. the first header with unknown type.
 * of unparsable area i.e. the first header with unknown type.
 * If it is not NULL *nexthdr is updated by type/protocol of this header.
 * If it is not NULL *nexthdr is updated by type/protocol of this header.
 *
 *
 * NOTES: - if packet terminated with NEXTHDR_NONE it returns NULL.
 * NOTES: - if packet terminated with NEXTHDR_NONE it returns NULL.
 *        - it may return pointer pointing beyond end of packet,
 *        - it may return pointer pointing beyond end of packet,
 *          if the last recognized header is truncated in the middle.
 *          if the last recognized header is truncated in the middle.
 *        - if packet is truncated, so that all parsed headers are skipped,
 *        - if packet is truncated, so that all parsed headers are skipped,
 *          it returns NULL.
 *          it returns NULL.
 *        - First fragment header is skipped, not-first ones
 *        - First fragment header is skipped, not-first ones
 *          are considered as unparsable.
 *          are considered as unparsable.
 *        - ESP is unparsable for now and considered like
 *        - ESP is unparsable for now and considered like
 *          normal payload protocol.
 *          normal payload protocol.
 *        - Note also special handling of AUTH header. Thanks to IPsec wizards.
 *        - Note also special handling of AUTH header. Thanks to IPsec wizards.
 *
 *
 * --ANK (980726)
 * --ANK (980726)
 */
 */
 
 
int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp)
int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp)
{
{
        u8 nexthdr = *nexthdrp;
        u8 nexthdr = *nexthdrp;
 
 
        while (ipv6_ext_hdr(nexthdr)) {
        while (ipv6_ext_hdr(nexthdr)) {
                struct ipv6_opt_hdr _hdr, *hp;
                struct ipv6_opt_hdr _hdr, *hp;
                int hdrlen;
                int hdrlen;
 
 
                if (nexthdr == NEXTHDR_NONE)
                if (nexthdr == NEXTHDR_NONE)
                        return -1;
                        return -1;
                hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
                hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
                if (hp == NULL)
                if (hp == NULL)
                        return -1;
                        return -1;
                if (nexthdr == NEXTHDR_FRAGMENT) {
                if (nexthdr == NEXTHDR_FRAGMENT) {
                        __be16 _frag_off, *fp;
                        __be16 _frag_off, *fp;
                        fp = skb_header_pointer(skb,
                        fp = skb_header_pointer(skb,
                                                start+offsetof(struct frag_hdr,
                                                start+offsetof(struct frag_hdr,
                                                               frag_off),
                                                               frag_off),
                                                sizeof(_frag_off),
                                                sizeof(_frag_off),
                                                &_frag_off);
                                                &_frag_off);
                        if (fp == NULL)
                        if (fp == NULL)
                                return -1;
                                return -1;
 
 
                        if (ntohs(*fp) & ~0x7)
                        if (ntohs(*fp) & ~0x7)
                                break;
                                break;
                        hdrlen = 8;
                        hdrlen = 8;
                } else if (nexthdr == NEXTHDR_AUTH)
                } else if (nexthdr == NEXTHDR_AUTH)
                        hdrlen = (hp->hdrlen+2)<<2;
                        hdrlen = (hp->hdrlen+2)<<2;
                else
                else
                        hdrlen = ipv6_optlen(hp);
                        hdrlen = ipv6_optlen(hp);
 
 
                nexthdr = hp->nexthdr;
                nexthdr = hp->nexthdr;
                start += hdrlen;
                start += hdrlen;
        }
        }
 
 
        *nexthdrp = nexthdr;
        *nexthdrp = nexthdr;
        return start;
        return start;
}
}
 
 
EXPORT_SYMBOL(ipv6_ext_hdr);
EXPORT_SYMBOL(ipv6_ext_hdr);
EXPORT_SYMBOL(ipv6_skip_exthdr);
EXPORT_SYMBOL(ipv6_skip_exthdr);
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.