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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [ax25/] [ax25_route.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.
 *
 *
 *      Other kernels modules in this kit are generally BSD derived. See the copyright headers.
 *      Other kernels modules in this kit are generally BSD derived. See the copyright headers.
 *
 *
 *
 *
 *      History
 *      History
 *      AX.25 020       Jonathan(G4KLX) First go.
 *      AX.25 020       Jonathan(G4KLX) First go.
 *      AX.25 022       Jonathan(G4KLX) Added the actual meat to this - we now have a nice heard list.
 *      AX.25 022       Jonathan(G4KLX) Added the actual meat to this - we now have a nice heard list.
 *      AX.25 025       Alan(GW4PTS)    First cut at autobinding by route scan.
 *      AX.25 025       Alan(GW4PTS)    First cut at autobinding by route scan.
 *      AX.25 028b      Jonathan(G4KLX) Extracted AX25 control block from the
 *      AX.25 028b      Jonathan(G4KLX) Extracted AX25 control block from the
 *                                      sock structure. Device removal now
 *                                      sock structure. Device removal now
 *                                      removes the heard structure.
 *                                      removes the heard structure.
 *      AX.25 029       Steven(GW7RRM)  Added /proc information for uid/callsign mapping.
 *      AX.25 029       Steven(GW7RRM)  Added /proc information for uid/callsign mapping.
 *                      Jonathan(G4KLX) Handling of IP mode in the routing list and /proc entry.
 *                      Jonathan(G4KLX) Handling of IP mode in the routing list and /proc entry.
 *      AX.25 030       Jonathan(G4KLX) Added digi-peaters to routing table, and
 *      AX.25 030       Jonathan(G4KLX) Added digi-peaters to routing table, and
 *                                      ioctls to manipulate them. Added port
 *                                      ioctls to manipulate them. Added port
 *                                      configuration.
 *                                      configuration.
 *      AX.25 031       Jonathan(G4KLX) Added concept of default route.
 *      AX.25 031       Jonathan(G4KLX) Added concept of default route.
 *                      Joerg(DL1BKE)   ax25_rt_build_path() find digipeater list and device by
 *                      Joerg(DL1BKE)   ax25_rt_build_path() find digipeater list and device by
 *                                      destination call. Needed for IP routing via digipeater
 *                                      destination call. Needed for IP routing via digipeater
 *                      Jonathan(G4KLX) Added routing for IP datagram packets.
 *                      Jonathan(G4KLX) Added routing for IP datagram packets.
 *                      Joerg(DL1BKE)   Changed routing for IP datagram and VC to use a default
 *                      Joerg(DL1BKE)   Changed routing for IP datagram and VC to use a default
 *                                      route if available. Does not overwrite default routes
 *                                      route if available. Does not overwrite default routes
 *                                      on route-table overflow anymore.
 *                                      on route-table overflow anymore.
 *                      Joerg(DL1BKE)   Fixed AX.25 routing of IP datagram and VC, new ioctl()
 *                      Joerg(DL1BKE)   Fixed AX.25 routing of IP datagram and VC, new ioctl()
 *                                      "SIOCAX25OPTRT" to set IP mode and a 'permanent' flag
 *                                      "SIOCAX25OPTRT" to set IP mode and a 'permanent' flag
 *                                      on routes.
 *                                      on routes.
 *      AX.25 033       Jonathan(G4KLX) Remove auto-router.
 *      AX.25 033       Jonathan(G4KLX) Remove auto-router.
 *                      Joerg(DL1BKE)   Moved BPQ Ethernet driver to separate device.
 *                      Joerg(DL1BKE)   Moved BPQ Ethernet driver to separate device.
 *      AX.25 035       Frederic(F1OAT) Support for pseudo-digipeating.
 *      AX.25 035       Frederic(F1OAT) Support for pseudo-digipeating.
 *                      Jonathan(G4KLX) Support for packet forwarding.
 *                      Jonathan(G4KLX) Support for packet forwarding.
 *                      Arnaldo C. Melo s/suser/capable/
 *                      Arnaldo C. Melo s/suser/capable/
 */
 */
 
 
#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/mm.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/init.h>
 
 
static ax25_route *ax25_route_list;
static ax25_route *ax25_route_list;
 
 
static ax25_route *ax25_find_route(ax25_address *, struct net_device *);
static ax25_route *ax25_find_route(ax25_address *, struct net_device *);
 
 
/*
/*
 * small macro to drop non-digipeated digipeaters and reverse path
 * small macro to drop non-digipeated digipeaters and reverse path
 */
 */
static inline void ax25_route_invert(ax25_digi *in, ax25_digi *out)
static inline void ax25_route_invert(ax25_digi *in, ax25_digi *out)
{
{
        int k;
        int k;
 
 
        for (k = 0; k < in->ndigi; k++)
        for (k = 0; k < in->ndigi; k++)
                if (!in->repeated[k])
                if (!in->repeated[k])
                        break;
                        break;
 
 
        in->ndigi = k;
        in->ndigi = k;
 
 
        ax25_digi_invert(in, out);
        ax25_digi_invert(in, out);
}
}
 
 
void ax25_rt_device_down(struct net_device *dev)
void ax25_rt_device_down(struct net_device *dev)
{
{
        ax25_route *s, *t, *ax25_rt = ax25_route_list;
        ax25_route *s, *t, *ax25_rt = ax25_route_list;
 
 
        while (ax25_rt != NULL) {
        while (ax25_rt != NULL) {
                s       = ax25_rt;
                s       = ax25_rt;
                ax25_rt = ax25_rt->next;
                ax25_rt = ax25_rt->next;
 
 
                if (s->dev == dev) {
                if (s->dev == dev) {
                        if (ax25_route_list == s) {
                        if (ax25_route_list == s) {
                                ax25_route_list = s->next;
                                ax25_route_list = s->next;
                                if (s->digipeat != NULL)
                                if (s->digipeat != NULL)
                                        kfree(s->digipeat);
                                        kfree(s->digipeat);
                                kfree(s);
                                kfree(s);
                        } else {
                        } else {
                                for (t = ax25_route_list; t != NULL; t = t->next) {
                                for (t = ax25_route_list; t != NULL; t = t->next) {
                                        if (t->next == s) {
                                        if (t->next == s) {
                                                t->next = s->next;
                                                t->next = s->next;
                                                if (s->digipeat != NULL)
                                                if (s->digipeat != NULL)
                                                        kfree(s->digipeat);
                                                        kfree(s->digipeat);
                                                kfree(s);
                                                kfree(s);
                                                break;
                                                break;
                                        }
                                        }
                                }
                                }
                        }
                        }
                }
                }
        }
        }
}
}
 
 
int ax25_rt_ioctl(unsigned int cmd, void *arg)
int ax25_rt_ioctl(unsigned int cmd, void *arg)
{
{
        unsigned long flags;
        unsigned long flags;
        ax25_route *s, *t, *ax25_rt;
        ax25_route *s, *t, *ax25_rt;
        struct ax25_routes_struct route;
        struct ax25_routes_struct route;
        struct ax25_route_opt_struct rt_option;
        struct ax25_route_opt_struct rt_option;
        ax25_dev *ax25_dev;
        ax25_dev *ax25_dev;
        int i;
        int i;
 
 
        switch (cmd) {
        switch (cmd) {
                case SIOCADDRT:
                case SIOCADDRT:
                        if (copy_from_user(&route, arg, sizeof(route)))
                        if (copy_from_user(&route, arg, sizeof(route)))
                                return -EFAULT;
                                return -EFAULT;
                        if ((ax25_dev = ax25_addr_ax25dev(&route.port_addr)) == NULL)
                        if ((ax25_dev = ax25_addr_ax25dev(&route.port_addr)) == NULL)
                                return -EINVAL;
                                return -EINVAL;
                        if (route.digi_count > AX25_MAX_DIGIS)
                        if (route.digi_count > AX25_MAX_DIGIS)
                                return -EINVAL;
                                return -EINVAL;
                        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
                        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
                                if (ax25cmp(&ax25_rt->callsign, &route.dest_addr) == 0 && ax25_rt->dev == ax25_dev->dev) {
                                if (ax25cmp(&ax25_rt->callsign, &route.dest_addr) == 0 && ax25_rt->dev == ax25_dev->dev) {
                                        if (ax25_rt->digipeat != NULL) {
                                        if (ax25_rt->digipeat != NULL) {
                                                kfree(ax25_rt->digipeat);
                                                kfree(ax25_rt->digipeat);
                                                ax25_rt->digipeat = NULL;
                                                ax25_rt->digipeat = NULL;
                                        }
                                        }
                                        if (route.digi_count != 0) {
                                        if (route.digi_count != 0) {
                                                if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL)
                                                if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL)
                                                        return -ENOMEM;
                                                        return -ENOMEM;
                                                ax25_rt->digipeat->lastrepeat = -1;
                                                ax25_rt->digipeat->lastrepeat = -1;
                                                ax25_rt->digipeat->ndigi      = route.digi_count;
                                                ax25_rt->digipeat->ndigi      = route.digi_count;
                                                for (i = 0; i < route.digi_count; i++) {
                                                for (i = 0; i < route.digi_count; i++) {
                                                        ax25_rt->digipeat->repeated[i] = 0;
                                                        ax25_rt->digipeat->repeated[i] = 0;
                                                        ax25_rt->digipeat->calls[i]    = route.digi_addr[i];
                                                        ax25_rt->digipeat->calls[i]    = route.digi_addr[i];
                                                }
                                                }
                                        }
                                        }
                                        return 0;
                                        return 0;
                                }
                                }
                        }
                        }
                        if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_ATOMIC)) == NULL)
                        if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_ATOMIC)) == NULL)
                                return -ENOMEM;
                                return -ENOMEM;
                        ax25_rt->callsign     = route.dest_addr;
                        ax25_rt->callsign     = route.dest_addr;
                        ax25_rt->dev          = ax25_dev->dev;
                        ax25_rt->dev          = ax25_dev->dev;
                        ax25_rt->digipeat     = NULL;
                        ax25_rt->digipeat     = NULL;
                        ax25_rt->ip_mode      = ' ';
                        ax25_rt->ip_mode      = ' ';
                        if (route.digi_count != 0) {
                        if (route.digi_count != 0) {
                                if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
                                if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
                                        kfree(ax25_rt);
                                        kfree(ax25_rt);
                                        return -ENOMEM;
                                        return -ENOMEM;
                                }
                                }
                                ax25_rt->digipeat->lastrepeat = -1;
                                ax25_rt->digipeat->lastrepeat = -1;
                                ax25_rt->digipeat->ndigi      = route.digi_count;
                                ax25_rt->digipeat->ndigi      = route.digi_count;
                                for (i = 0; i < route.digi_count; i++) {
                                for (i = 0; i < route.digi_count; i++) {
                                        ax25_rt->digipeat->repeated[i] = 0;
                                        ax25_rt->digipeat->repeated[i] = 0;
                                        ax25_rt->digipeat->calls[i]    = route.digi_addr[i];
                                        ax25_rt->digipeat->calls[i]    = route.digi_addr[i];
                                }
                                }
                        }
                        }
                        save_flags(flags); cli();
                        save_flags(flags); cli();
                        ax25_rt->next   = ax25_route_list;
                        ax25_rt->next   = ax25_route_list;
                        ax25_route_list = ax25_rt;
                        ax25_route_list = ax25_rt;
                        restore_flags(flags);
                        restore_flags(flags);
                        break;
                        break;
 
 
                case SIOCDELRT:
                case SIOCDELRT:
                        if (copy_from_user(&route, arg, sizeof(route)))
                        if (copy_from_user(&route, arg, sizeof(route)))
                                return -EFAULT;
                                return -EFAULT;
                        if ((ax25_dev = ax25_addr_ax25dev(&route.port_addr)) == NULL)
                        if ((ax25_dev = ax25_addr_ax25dev(&route.port_addr)) == NULL)
                                return -EINVAL;
                                return -EINVAL;
                        ax25_rt = ax25_route_list;
                        ax25_rt = ax25_route_list;
                        while (ax25_rt != NULL) {
                        while (ax25_rt != NULL) {
                                s       = ax25_rt;
                                s       = ax25_rt;
                                ax25_rt = ax25_rt->next;
                                ax25_rt = ax25_rt->next;
                                if (s->dev == ax25_dev->dev && ax25cmp(&route.dest_addr, &s->callsign) == 0) {
                                if (s->dev == ax25_dev->dev && ax25cmp(&route.dest_addr, &s->callsign) == 0) {
                                        if (ax25_route_list == s) {
                                        if (ax25_route_list == s) {
                                                ax25_route_list = s->next;
                                                ax25_route_list = s->next;
                                                if (s->digipeat != NULL)
                                                if (s->digipeat != NULL)
                                                        kfree(s->digipeat);
                                                        kfree(s->digipeat);
                                                kfree(s);
                                                kfree(s);
                                        } else {
                                        } else {
                                                for (t = ax25_route_list; t != NULL; t = t->next) {
                                                for (t = ax25_route_list; t != NULL; t = t->next) {
                                                        if (t->next == s) {
                                                        if (t->next == s) {
                                                                t->next = s->next;
                                                                t->next = s->next;
                                                                if (s->digipeat != NULL)
                                                                if (s->digipeat != NULL)
                                                                        kfree(s->digipeat);
                                                                        kfree(s->digipeat);
                                                                kfree(s);
                                                                kfree(s);
                                                                break;
                                                                break;
                                                        }
                                                        }
                                                }
                                                }
                                        }
                                        }
                                }
                                }
                        }
                        }
                        break;
                        break;
 
 
                case SIOCAX25OPTRT:
                case SIOCAX25OPTRT:
                        if (copy_from_user(&rt_option, arg, sizeof(rt_option)))
                        if (copy_from_user(&rt_option, arg, sizeof(rt_option)))
                                return -EFAULT;
                                return -EFAULT;
                        if ((ax25_dev = ax25_addr_ax25dev(&rt_option.port_addr)) == NULL)
                        if ((ax25_dev = ax25_addr_ax25dev(&rt_option.port_addr)) == NULL)
                                return -EINVAL;
                                return -EINVAL;
                        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
                        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
                                if (ax25_rt->dev == ax25_dev->dev && ax25cmp(&rt_option.dest_addr, &ax25_rt->callsign) == 0) {
                                if (ax25_rt->dev == ax25_dev->dev && ax25cmp(&rt_option.dest_addr, &ax25_rt->callsign) == 0) {
                                        switch (rt_option.cmd) {
                                        switch (rt_option.cmd) {
                                                case AX25_SET_RT_IPMODE:
                                                case AX25_SET_RT_IPMODE:
                                                        switch (rt_option.arg) {
                                                        switch (rt_option.arg) {
                                                                case ' ':
                                                                case ' ':
                                                                case 'D':
                                                                case 'D':
                                                                case 'V':
                                                                case 'V':
                                                                        ax25_rt->ip_mode = rt_option.arg;
                                                                        ax25_rt->ip_mode = rt_option.arg;
                                                                        break;
                                                                        break;
                                                                default:
                                                                default:
                                                                        return -EINVAL;
                                                                        return -EINVAL;
                                                        }
                                                        }
                                                        break;
                                                        break;
                                                default:
                                                default:
                                                        return -EINVAL;
                                                        return -EINVAL;
                                        }
                                        }
                                }
                                }
                        }
                        }
                        break;
                        break;
 
 
                default:
                default:
                        return -EINVAL;
                        return -EINVAL;
        }
        }
 
 
        return 0;
        return 0;
}
}
 
 
int ax25_rt_get_info(char *buffer, char **start, off_t offset, int length)
int ax25_rt_get_info(char *buffer, char **start, off_t offset, int length)
{
{
        ax25_route *ax25_rt;
        ax25_route *ax25_rt;
        int len     = 0;
        int len     = 0;
        off_t pos   = 0;
        off_t pos   = 0;
        off_t begin = 0;
        off_t begin = 0;
        char *callsign;
        char *callsign;
        int i;
        int i;
 
 
        cli();
        cli();
 
 
        len += sprintf(buffer, "callsign  dev  mode digipeaters\n");
        len += sprintf(buffer, "callsign  dev  mode digipeaters\n");
 
 
        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
                if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0)
                if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0)
                        callsign = "default";
                        callsign = "default";
                else
                else
                        callsign = ax2asc(&ax25_rt->callsign);
                        callsign = ax2asc(&ax25_rt->callsign);
                len += sprintf(buffer + len, "%-9s %-4s",
                len += sprintf(buffer + len, "%-9s %-4s",
                        callsign,
                        callsign,
                        ax25_rt->dev ? ax25_rt->dev->name : "???");
                        ax25_rt->dev ? ax25_rt->dev->name : "???");
 
 
                switch (ax25_rt->ip_mode) {
                switch (ax25_rt->ip_mode) {
                        case 'V':
                        case 'V':
                                len += sprintf(buffer + len, "   vc");
                                len += sprintf(buffer + len, "   vc");
                                break;
                                break;
                        case 'D':
                        case 'D':
                                len += sprintf(buffer + len, "   dg");
                                len += sprintf(buffer + len, "   dg");
                                break;
                                break;
                        default:
                        default:
                                len += sprintf(buffer + len, "    *");
                                len += sprintf(buffer + len, "    *");
                                break;
                                break;
                }
                }
 
 
                if (ax25_rt->digipeat != NULL)
                if (ax25_rt->digipeat != NULL)
                        for (i = 0; i < ax25_rt->digipeat->ndigi; i++)
                        for (i = 0; i < ax25_rt->digipeat->ndigi; i++)
                                len += sprintf(buffer + len, " %s", ax2asc(&ax25_rt->digipeat->calls[i]));
                                len += sprintf(buffer + len, " %s", ax2asc(&ax25_rt->digipeat->calls[i]));
 
 
                len += sprintf(buffer + len, "\n");
                len += sprintf(buffer + len, "\n");
 
 
                pos = begin + len;
                pos = begin + len;
 
 
                if (pos < offset) {
                if (pos < offset) {
                        len   = 0;
                        len   = 0;
                        begin = pos;
                        begin = pos;
                }
                }
 
 
                if (pos > offset + length)
                if (pos > offset + length)
                        break;
                        break;
        }
        }
 
 
        sti();
        sti();
 
 
        *start = buffer + (offset - begin);
        *start = buffer + (offset - begin);
        len   -= (offset - begin);
        len   -= (offset - begin);
 
 
        if (len > length) len = length;
        if (len > length) len = length;
 
 
        return len;
        return len;
}
}
 
 
/*
/*
 *      Find AX.25 route
 *      Find AX.25 route
 */
 */
static ax25_route *ax25_find_route(ax25_address *addr, struct net_device *dev)
static ax25_route *ax25_find_route(ax25_address *addr, struct net_device *dev)
{
{
        ax25_route *ax25_spe_rt = NULL;
        ax25_route *ax25_spe_rt = NULL;
        ax25_route *ax25_def_rt = NULL;
        ax25_route *ax25_def_rt = NULL;
        ax25_route *ax25_rt;
        ax25_route *ax25_rt;
 
 
        /*
        /*
         *      Bind to the physical interface we heard them on, or the default
         *      Bind to the physical interface we heard them on, or the default
         *      route if none is found;
         *      route if none is found;
         */
         */
        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
        for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
                if (dev == NULL) {
                if (dev == NULL) {
                        if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev != NULL)
                        if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev != NULL)
                                ax25_spe_rt = ax25_rt;
                                ax25_spe_rt = ax25_rt;
                        if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev != NULL)
                        if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev != NULL)
                                ax25_def_rt = ax25_rt;
                                ax25_def_rt = ax25_rt;
                } else {
                } else {
                        if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev == dev)
                        if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev == dev)
                                ax25_spe_rt = ax25_rt;
                                ax25_spe_rt = ax25_rt;
                        if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev == dev)
                        if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev == dev)
                                ax25_def_rt = ax25_rt;
                                ax25_def_rt = ax25_rt;
                }
                }
        }
        }
 
 
        if (ax25_spe_rt != NULL)
        if (ax25_spe_rt != NULL)
                return ax25_spe_rt;
                return ax25_spe_rt;
 
 
        return ax25_def_rt;
        return ax25_def_rt;
}
}
 
 
/*
/*
 *      Adjust path: If you specify a default route and want to connect
 *      Adjust path: If you specify a default route and want to connect
 *      a target on the digipeater path but w/o having a special route
 *      a target on the digipeater path but w/o having a special route
 *      set before, the path has to be truncated from your target on.
 *      set before, the path has to be truncated from your target on.
 */
 */
static inline void ax25_adjust_path(ax25_address *addr, ax25_digi *digipeat)
static inline void ax25_adjust_path(ax25_address *addr, ax25_digi *digipeat)
{
{
        int k;
        int k;
 
 
        for (k = 0; k < digipeat->ndigi; k++) {
        for (k = 0; k < digipeat->ndigi; k++) {
                if (ax25cmp(addr, &digipeat->calls[k]) == 0)
                if (ax25cmp(addr, &digipeat->calls[k]) == 0)
                        break;
                        break;
        }
        }
 
 
        digipeat->ndigi = k;
        digipeat->ndigi = k;
}
}
 
 
 
 
/*
/*
 *      Find which interface to use.
 *      Find which interface to use.
 */
 */
int ax25_rt_autobind(ax25_cb *ax25, ax25_address *addr)
int ax25_rt_autobind(ax25_cb *ax25, ax25_address *addr)
{
{
        ax25_route *ax25_rt;
        ax25_route *ax25_rt;
        ax25_address *call;
        ax25_address *call;
 
 
        if ((ax25_rt = ax25_find_route(addr, NULL)) == NULL)
        if ((ax25_rt = ax25_find_route(addr, NULL)) == NULL)
                return -EHOSTUNREACH;
                return -EHOSTUNREACH;
 
 
        if ((ax25->ax25_dev = ax25_dev_ax25dev(ax25_rt->dev)) == NULL)
        if ((ax25->ax25_dev = ax25_dev_ax25dev(ax25_rt->dev)) == NULL)
                return -EHOSTUNREACH;
                return -EHOSTUNREACH;
 
 
        if ((call = ax25_findbyuid(current->euid)) == NULL) {
        if ((call = ax25_findbyuid(current->euid)) == NULL) {
                if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE))
                if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE))
                        return -EPERM;
                        return -EPERM;
                call = (ax25_address *)ax25->ax25_dev->dev->dev_addr;
                call = (ax25_address *)ax25->ax25_dev->dev->dev_addr;
        }
        }
 
 
        ax25->source_addr = *call;
        ax25->source_addr = *call;
 
 
        if (ax25_rt->digipeat != NULL) {
        if (ax25_rt->digipeat != NULL) {
                if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL)
                if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL)
                        return -ENOMEM;
                        return -ENOMEM;
                memcpy(ax25->digipeat, ax25_rt->digipeat, sizeof(ax25_digi));
                memcpy(ax25->digipeat, ax25_rt->digipeat, sizeof(ax25_digi));
                ax25_adjust_path(addr, ax25->digipeat);
                ax25_adjust_path(addr, ax25->digipeat);
        }
        }
 
 
        if (ax25->sk != NULL)
        if (ax25->sk != NULL)
                ax25->sk->zapped = 0;
                ax25->sk->zapped = 0;
 
 
        return 0;
        return 0;
}
}
 
 
/*
/*
 *      dl1bke 960117: build digipeater path
 *      dl1bke 960117: build digipeater path
 *      dl1bke 960301: use the default route if it exists
 *      dl1bke 960301: use the default route if it exists
 */
 */
ax25_route *ax25_rt_find_route(ax25_address *addr, struct net_device *dev)
ax25_route *ax25_rt_find_route(ax25_address *addr, struct net_device *dev)
{
{
        static ax25_route route;
        static ax25_route route;
        ax25_route *ax25_rt;
        ax25_route *ax25_rt;
 
 
        if ((ax25_rt = ax25_find_route(addr, dev)) == NULL) {
        if ((ax25_rt = ax25_find_route(addr, dev)) == NULL) {
                route.next     = NULL;
                route.next     = NULL;
                route.callsign = *addr;
                route.callsign = *addr;
                route.dev      = dev;
                route.dev      = dev;
                route.digipeat = NULL;
                route.digipeat = NULL;
                route.ip_mode  = ' ';
                route.ip_mode  = ' ';
                return &route;
                return &route;
        }
        }
 
 
        return ax25_rt;
        return ax25_rt;
}
}
 
 
struct sk_buff *ax25_rt_build_path(struct sk_buff *skb, ax25_address *src, ax25_address *dest, ax25_digi *digi)
struct sk_buff *ax25_rt_build_path(struct sk_buff *skb, ax25_address *src, ax25_address *dest, ax25_digi *digi)
{
{
        struct sk_buff *skbn;
        struct sk_buff *skbn;
        unsigned char *bp;
        unsigned char *bp;
        int len;
        int len;
 
 
        len = digi->ndigi * AX25_ADDR_LEN;
        len = digi->ndigi * AX25_ADDR_LEN;
 
 
        if (skb_headroom(skb) < len) {
        if (skb_headroom(skb) < len) {
                if ((skbn = skb_realloc_headroom(skb, len)) == NULL) {
                if ((skbn = skb_realloc_headroom(skb, len)) == NULL) {
                        printk(KERN_CRIT "AX.25: ax25_dg_build_path - out of memory\n");
                        printk(KERN_CRIT "AX.25: ax25_dg_build_path - out of memory\n");
                        return NULL;
                        return NULL;
                }
                }
 
 
                if (skb->sk != NULL)
                if (skb->sk != NULL)
                        skb_set_owner_w(skbn, skb->sk);
                        skb_set_owner_w(skbn, skb->sk);
 
 
                kfree_skb(skb);
                kfree_skb(skb);
 
 
                skb = skbn;
                skb = skbn;
        }
        }
 
 
        bp = skb_push(skb, len);
        bp = skb_push(skb, len);
 
 
        ax25_addr_build(bp, src, dest, digi, AX25_COMMAND, AX25_MODULUS);
        ax25_addr_build(bp, src, dest, digi, AX25_COMMAND, AX25_MODULUS);
 
 
        return skb;
        return skb;
}
}
 
 
/*
/*
 *      Free all memory associated with routing structures.
 *      Free all memory associated with routing structures.
 */
 */
void __exit ax25_rt_free(void)
void __exit ax25_rt_free(void)
{
{
        ax25_route *s, *ax25_rt = ax25_route_list;
        ax25_route *s, *ax25_rt = ax25_route_list;
 
 
        while (ax25_rt != NULL) {
        while (ax25_rt != NULL) {
                s       = ax25_rt;
                s       = ax25_rt;
                ax25_rt = ax25_rt->next;
                ax25_rt = ax25_rt->next;
 
 
                if (s->digipeat != NULL)
                if (s->digipeat != NULL)
                        kfree(s->digipeat);
                        kfree(s->digipeat);
 
 
                kfree(s);
                kfree(s);
        }
        }
}
}
 
 

powered by: WebSVN 2.1.0

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