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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [ax25/] [ax25_ip.c] - Diff between revs 1275 and 1765

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

Rev 1275 Rev 1765
/*
/*
 *      AX.25 release 037
 *      AX.25 release 037
 *
 *
 *      This code REQUIRES 2.1.15 or higher/ NET3.038
 *      This code REQUIRES 2.1.15 or higher/ NET3.038
 *
 *
 *      This module:
 *      This module:
 *              This module is free software; you can redistribute it and/or
 *              This module is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU General Public License
 *              modify it under the terms of the GNU General Public License
 *              as published by the Free Software Foundation; either version
 *              as published by the Free Software Foundation; either version
 *              2 of the License, or (at your option) any later version.
 *              2 of the License, or (at your option) any later version.
 *
 *
 *      History
 *      History
 *      AX.25 036       Jonathan(G4KLX) Split from af_ax25.c.
 *      AX.25 036       Jonathan(G4KLX) Split from af_ax25.c.
 */
 */
 
 
#include <linux/config.h>
#include <linux/config.h>
#include <linux/errno.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/in.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/string.h>
#include <linux/sockios.h>
#include <linux/sockios.h>
#include <linux/net.h>
#include <linux/net.h>
#include <net/ax25.h>
#include <net/ax25.h>
#include <linux/inet.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/if_arp.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <net/sock.h>
#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/system.h>
#include <linux/fcntl.h>
#include <linux/fcntl.h>
#include <linux/termios.h>      /* For TIOCINQ/OUTQ */
#include <linux/termios.h>      /* For TIOCINQ/OUTQ */
#include <linux/mm.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/notifier.h>
#include <linux/proc_fs.h>
#include <linux/proc_fs.h>
#include <linux/stat.h>
#include <linux/stat.h>
#include <linux/netfilter.h>
#include <linux/netfilter.h>
#include <linux/sysctl.h>
#include <linux/sysctl.h>
#include <net/ip.h>
#include <net/ip.h>
#include <net/arp.h>
#include <net/arp.h>
 
 
/*
/*
 *      IP over AX.25 encapsulation.
 *      IP over AX.25 encapsulation.
 */
 */
 
 
/*
/*
 *      Shove an AX.25 UI header on an IP packet and handle ARP
 *      Shove an AX.25 UI header on an IP packet and handle ARP
 */
 */
 
 
#ifdef CONFIG_INET
#ifdef CONFIG_INET
 
 
int ax25_encapsulate(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len)
int ax25_encapsulate(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len)
{
{
        unsigned char *buff;
        unsigned char *buff;
 
 
        /* they sometimes come back to us... */
        /* they sometimes come back to us... */
        if (type == ETH_P_AX25)
        if (type == ETH_P_AX25)
                return 0;
                return 0;
 
 
        /* header is an AX.25 UI frame from us to them */
        /* header is an AX.25 UI frame from us to them */
        buff = skb_push(skb, AX25_HEADER_LEN);
        buff = skb_push(skb, AX25_HEADER_LEN);
        *buff++ = 0x00; /* KISS DATA */
        *buff++ = 0x00; /* KISS DATA */
 
 
        if (daddr != NULL)
        if (daddr != NULL)
                memcpy(buff, daddr, dev->addr_len);     /* Address specified */
                memcpy(buff, daddr, dev->addr_len);     /* Address specified */
 
 
        buff[6] &= ~AX25_CBIT;
        buff[6] &= ~AX25_CBIT;
        buff[6] &= ~AX25_EBIT;
        buff[6] &= ~AX25_EBIT;
        buff[6] |= AX25_SSSID_SPARE;
        buff[6] |= AX25_SSSID_SPARE;
        buff    += AX25_ADDR_LEN;
        buff    += AX25_ADDR_LEN;
 
 
        if (saddr != NULL)
        if (saddr != NULL)
                memcpy(buff, saddr, dev->addr_len);
                memcpy(buff, saddr, dev->addr_len);
        else
        else
                memcpy(buff, dev->dev_addr, dev->addr_len);
                memcpy(buff, dev->dev_addr, dev->addr_len);
 
 
        buff[6] &= ~AX25_CBIT;
        buff[6] &= ~AX25_CBIT;
        buff[6] |= AX25_EBIT;
        buff[6] |= AX25_EBIT;
        buff[6] |= AX25_SSSID_SPARE;
        buff[6] |= AX25_SSSID_SPARE;
        buff    += AX25_ADDR_LEN;
        buff    += AX25_ADDR_LEN;
 
 
        *buff++  = AX25_UI;     /* UI */
        *buff++  = AX25_UI;     /* UI */
 
 
        /* Append a suitable AX.25 PID */
        /* Append a suitable AX.25 PID */
        switch (type) {
        switch (type) {
                case ETH_P_IP:
                case ETH_P_IP:
                        *buff++ = AX25_P_IP;
                        *buff++ = AX25_P_IP;
                        break;
                        break;
                case ETH_P_ARP:
                case ETH_P_ARP:
                        *buff++ = AX25_P_ARP;
                        *buff++ = AX25_P_ARP;
                        break;
                        break;
                default:
                default:
                        printk(KERN_ERR "AX.25: ax25_encapsulate - wrong protocol type 0x%2.2x\n", type);
                        printk(KERN_ERR "AX.25: ax25_encapsulate - wrong protocol type 0x%2.2x\n", type);
                        *buff++ = 0;
                        *buff++ = 0;
                        break;
                        break;
        }
        }
 
 
        if (daddr != NULL)
        if (daddr != NULL)
                return AX25_HEADER_LEN;
                return AX25_HEADER_LEN;
 
 
        return -AX25_HEADER_LEN;        /* Unfinished header */
        return -AX25_HEADER_LEN;        /* Unfinished header */
}
}
 
 
int ax25_rebuild_header(struct sk_buff *skb)
int ax25_rebuild_header(struct sk_buff *skb)
{
{
        struct sk_buff *ourskb;
        struct sk_buff *ourskb;
        unsigned char *bp  = skb->data;
        unsigned char *bp  = skb->data;
        struct net_device *dev;
        struct net_device *dev;
        ax25_address *src, *dst;
        ax25_address *src, *dst;
        ax25_route *route;
        ax25_route *route;
        ax25_dev *ax25_dev;
        ax25_dev *ax25_dev;
 
 
        dst = (ax25_address *)(bp + 1);
        dst = (ax25_address *)(bp + 1);
        src = (ax25_address *)(bp + 8);
        src = (ax25_address *)(bp + 8);
 
 
        if (arp_find(bp + 1, skb))
        if (arp_find(bp + 1, skb))
                return 1;
                return 1;
 
 
        route    = ax25_rt_find_route(dst, NULL);
        route    = ax25_rt_find_route(dst, NULL);
        dev      = route->dev;
        dev      = route->dev;
 
 
        if (dev == NULL)
        if (dev == NULL)
                dev = skb->dev;
                dev = skb->dev;
 
 
        if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
        if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
                return 1;
                return 1;
 
 
        if (bp[16] == AX25_P_IP) {
        if (bp[16] == AX25_P_IP) {
                if (route->ip_mode == 'V' || (route->ip_mode == ' ' && ax25_dev->values[AX25_VALUES_IPDEFMODE])) {
                if (route->ip_mode == 'V' || (route->ip_mode == ' ' && ax25_dev->values[AX25_VALUES_IPDEFMODE])) {
                        /*
                        /*
                         *      We copy the buffer and release the original thereby
                         *      We copy the buffer and release the original thereby
                         *      keeping it straight
                         *      keeping it straight
                         *
                         *
                         *      Note: we report 1 back so the caller will
                         *      Note: we report 1 back so the caller will
                         *      not feed the frame direct to the physical device
                         *      not feed the frame direct to the physical device
                         *      We don't want that to happen. (It won't be upset
                         *      We don't want that to happen. (It won't be upset
                         *      as we have pulled the frame from the queue by
                         *      as we have pulled the frame from the queue by
                         *      freeing it).
                         *      freeing it).
                         *
                         *
                         *      NB: TCP modifies buffers that are still
                         *      NB: TCP modifies buffers that are still
                         *      on a device queue, thus we use skb_copy()
                         *      on a device queue, thus we use skb_copy()
                         *      instead of using skb_clone() unless this
                         *      instead of using skb_clone() unless this
                         *      gets fixed.
                         *      gets fixed.
                         */
                         */
 
 
                        ax25_address src_c;
                        ax25_address src_c;
                        ax25_address dst_c;
                        ax25_address dst_c;
 
 
                        if ((ourskb = skb_copy(skb, GFP_ATOMIC)) == NULL) {
                        if ((ourskb = skb_copy(skb, GFP_ATOMIC)) == NULL) {
                                kfree_skb(skb);
                                kfree_skb(skb);
                                return 1;
                                return 1;
                        }
                        }
 
 
                        if (skb->sk != NULL)
                        if (skb->sk != NULL)
                                skb_set_owner_w(ourskb, skb->sk);
                                skb_set_owner_w(ourskb, skb->sk);
 
 
                        kfree_skb(skb);
                        kfree_skb(skb);
                        /* dl9sau: bugfix
                        /* dl9sau: bugfix
                         * after kfree_skb(), dst and src which were pointer
                         * after kfree_skb(), dst and src which were pointer
                         * to bp which is part of skb->data would not be valid
                         * to bp which is part of skb->data would not be valid
                         * anymore hope that after skb_pull(ourskb, ..) our
                         * anymore hope that after skb_pull(ourskb, ..) our
                         * dsc_c and src_c will not become invalid
                         * dsc_c and src_c will not become invalid
                         */
                         */
                        bp  = ourskb->data;
                        bp  = ourskb->data;
                        dst_c = *(ax25_address *)(bp + 1);
                        dst_c = *(ax25_address *)(bp + 1);
                        src_c = *(ax25_address *)(bp + 8);
                        src_c = *(ax25_address *)(bp + 8);
 
 
                        skb_pull(ourskb, AX25_HEADER_LEN - 1);  /* Keep PID */
                        skb_pull(ourskb, AX25_HEADER_LEN - 1);  /* Keep PID */
                        ourskb->nh.raw = ourskb->data;
                        ourskb->nh.raw = ourskb->data;
 
 
                        ax25_send_frame(ourskb, ax25_dev->values[AX25_VALUES_PACLEN], &src_c,
                        ax25_send_frame(ourskb, ax25_dev->values[AX25_VALUES_PACLEN], &src_c,
&dst_c, route->digipeat, dev);
&dst_c, route->digipeat, dev);
 
 
                        return 1;
                        return 1;
                }
                }
        }
        }
 
 
        bp[7]  &= ~AX25_CBIT;
        bp[7]  &= ~AX25_CBIT;
        bp[7]  &= ~AX25_EBIT;
        bp[7]  &= ~AX25_EBIT;
        bp[7]  |= AX25_SSSID_SPARE;
        bp[7]  |= AX25_SSSID_SPARE;
 
 
        bp[14] &= ~AX25_CBIT;
        bp[14] &= ~AX25_CBIT;
        bp[14] |= AX25_EBIT;
        bp[14] |= AX25_EBIT;
        bp[14] |= AX25_SSSID_SPARE;
        bp[14] |= AX25_SSSID_SPARE;
 
 
        skb_pull(skb, AX25_KISS_HEADER_LEN);
        skb_pull(skb, AX25_KISS_HEADER_LEN);
 
 
        if (route->digipeat != NULL) {
        if (route->digipeat != NULL) {
                if ((ourskb = ax25_rt_build_path(skb, src, dst, route->digipeat)) == NULL) {
                if ((ourskb = ax25_rt_build_path(skb, src, dst, route->digipeat)) == NULL) {
                        kfree_skb(skb);
                        kfree_skb(skb);
                        return 1;
                        return 1;
                }
                }
 
 
                skb = ourskb;
                skb = ourskb;
        }
        }
 
 
        skb->dev      = dev;
        skb->dev      = dev;
 
 
        ax25_queue_xmit(skb);
        ax25_queue_xmit(skb);
 
 
        return 1;
        return 1;
}
}
 
 
#else   /* INET */
#else   /* INET */
 
 
int ax25_encapsulate(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len)
int ax25_encapsulate(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len)
{
{
        return -AX25_HEADER_LEN;
        return -AX25_HEADER_LEN;
}
}
 
 
int ax25_rebuild_header(struct sk_buff *skb)
int ax25_rebuild_header(struct sk_buff *skb)
{
{
        return 1;
        return 1;
}
}
 
 
#endif
#endif
 
 
 
 

powered by: WebSVN 2.1.0

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