Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) Steven Whitehouse GW7RRM (stevew@acm.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static ax25_route *ax25_route_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) DEFINE_RWLOCK(ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) void ax25_rt_device_down(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	ax25_route *s, *t, *ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	write_lock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	ax25_rt = ax25_route_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	while (ax25_rt != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		s       = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		ax25_rt = ax25_rt->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		if (s->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			if (ax25_route_list == s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 				ax25_route_list = s->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 				kfree(s->digipeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				for (t = ax25_route_list; t != NULL; t = t->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 					if (t->next == s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 						t->next = s->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 						kfree(s->digipeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 						kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 						break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	ax25_route *ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	ax25_dev *ax25_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if ((ax25_dev = ax25_addr_ax25dev(&route->port_addr)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (route->digi_count > AX25_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	write_lock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	ax25_rt = ax25_route_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	while (ax25_rt != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			    ax25_rt->dev == ax25_dev->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			kfree(ax25_rt->digipeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			ax25_rt->digipeat = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			if (route->digi_count != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 					write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				ax25_rt->digipeat->lastrepeat = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				ax25_rt->digipeat->ndigi      = route->digi_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				for (i = 0; i < route->digi_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 					ax25_rt->digipeat->repeated[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 					ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		ax25_rt = ax25_rt->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_ATOMIC)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	refcount_set(&ax25_rt->refcount, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ax25_rt->callsign     = route->dest_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	ax25_rt->dev          = ax25_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	ax25_rt->digipeat     = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	ax25_rt->ip_mode      = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (route->digi_count != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			kfree(ax25_rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		ax25_rt->digipeat->lastrepeat = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		ax25_rt->digipeat->ndigi      = route->digi_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		for (i = 0; i < route->digi_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			ax25_rt->digipeat->repeated[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	ax25_rt->next   = ax25_route_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ax25_route_list = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void __ax25_put_route(ax25_route *ax25_rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	kfree(ax25_rt->digipeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	kfree(ax25_rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int ax25_rt_del(struct ax25_routes_struct *route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ax25_route *s, *t, *ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	ax25_dev *ax25_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if ((ax25_dev = ax25_addr_ax25dev(&route->port_addr)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	write_lock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	ax25_rt = ax25_route_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	while (ax25_rt != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		s       = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		ax25_rt = ax25_rt->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		if (s->dev == ax25_dev->dev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		    ax25cmp(&route->dest_addr, &s->callsign) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			if (ax25_route_list == s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				ax25_route_list = s->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				ax25_put_route(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				for (t = ax25_route_list; t != NULL; t = t->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 					if (t->next == s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 						t->next = s->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 						ax25_put_route(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 						break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int ax25_rt_opt(struct ax25_route_opt_struct *rt_option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	ax25_route *ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	ax25_dev *ax25_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if ((ax25_dev = ax25_addr_ax25dev(&rt_option->port_addr)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	write_lock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	ax25_rt = ax25_route_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	while (ax25_rt != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (ax25_rt->dev == ax25_dev->dev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		    ax25cmp(&rt_option->dest_addr, &ax25_rt->callsign) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			switch (rt_option->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			case AX25_SET_RT_IPMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				switch (rt_option->arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				case ' ':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				case 'D':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				case 'V':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 					ax25_rt->ip_mode = rt_option->arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 				default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 					err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 					goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		ax25_rt = ax25_rt->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int ax25_rt_ioctl(unsigned int cmd, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct ax25_route_opt_struct rt_option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct ax25_routes_struct route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (copy_from_user(&route, arg, sizeof(route)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return ax25_rt_add(&route);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (copy_from_user(&route, arg, sizeof(route)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return ax25_rt_del(&route);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	case SIOCAX25OPTRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		if (copy_from_user(&rt_option, arg, sizeof(rt_option)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return ax25_rt_opt(&rt_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static void *ax25_rt_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	__acquires(ax25_route_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct ax25_route *ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	read_lock(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (*pos == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		return SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (i == *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			return ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		++i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static void *ax25_rt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return (v == SEQ_START_TOKEN) ? ax25_route_list :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		((struct ax25_route *) v)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static void ax25_rt_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	__releases(ax25_route_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	read_unlock(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static int ax25_rt_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	char buf[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		seq_puts(seq, "callsign  dev  mode digipeaters\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		struct ax25_route *ax25_rt = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		const char *callsign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			callsign = "default";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			callsign = ax2asc(buf, &ax25_rt->callsign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		seq_printf(seq, "%-9s %-4s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			callsign,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			ax25_rt->dev ? ax25_rt->dev->name : "???");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		switch (ax25_rt->ip_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		case 'V':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			seq_puts(seq, "   vc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		case 'D':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			seq_puts(seq, "   dg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			seq_puts(seq, "    *");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if (ax25_rt->digipeat != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			for (i = 0; i < ax25_rt->digipeat->ndigi; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 				seq_printf(seq, " %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				     ax2asc(buf, &ax25_rt->digipeat->calls[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		seq_puts(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) const struct seq_operations ax25_rt_seqops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	.start = ax25_rt_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.next = ax25_rt_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.stop = ax25_rt_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	.show = ax25_rt_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  *	Find AX.25 route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  *	Only routes with a reference count of zero can be destroyed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  *	Must be called with ax25_route_lock read locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ax25_route *ax25_get_route(ax25_address *addr, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	ax25_route *ax25_spe_rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	ax25_route *ax25_def_rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	ax25_route *ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 *	Bind to the physical interface we heard them on, or the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 *	route if none is found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	for (ax25_rt = ax25_route_list; ax25_rt != NULL; ax25_rt = ax25_rt->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		if (dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 				ax25_spe_rt = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				ax25_def_rt = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			if (ax25cmp(&ax25_rt->callsign, addr) == 0 && ax25_rt->dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 				ax25_spe_rt = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				ax25_def_rt = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	ax25_rt = ax25_def_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (ax25_spe_rt != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		ax25_rt = ax25_spe_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  *	Adjust path: If you specify a default route and want to connect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  *      a target on the digipeater path but w/o having a special route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  *	set before, the path has to be truncated from your target on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static inline void ax25_adjust_path(ax25_address *addr, ax25_digi *digipeat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	for (k = 0; k < digipeat->ndigi; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		if (ax25cmp(addr, &digipeat->calls[k]) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	digipeat->ndigi = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  *	Find which interface to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int ax25_rt_autobind(ax25_cb *ax25, ax25_address *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	ax25_uid_assoc *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	ax25_route *ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	ax25_route_lock_use();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	ax25_rt = ax25_get_route(addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (!ax25_rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		ax25_route_lock_unuse();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		return -EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	if ((ax25->ax25_dev = ax25_dev_ax25dev(ax25_rt->dev)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		err = -EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	user = ax25_findbyuid(current_euid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		ax25->source_addr = user->call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		ax25_uid_put(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		ax25->source_addr = *(ax25_address *)ax25->ax25_dev->dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (ax25_rt->digipeat != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		ax25->digipeat = kmemdup(ax25_rt->digipeat, sizeof(ax25_digi),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 					 GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		if (ax25->digipeat == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		ax25_adjust_path(addr, ax25->digipeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (ax25->sk != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		bh_lock_sock(ax25->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		sock_reset_flag(ax25->sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		bh_unlock_sock(ax25->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	ax25_route_lock_unuse();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct sk_buff *ax25_rt_build_path(struct sk_buff *skb, ax25_address *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	ax25_address *dest, ax25_digi *digi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	struct sk_buff *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	unsigned char *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	len = digi->ndigi * AX25_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (skb_headroom(skb) < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		if ((skbn = skb_realloc_headroom(skb, len)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			printk(KERN_CRIT "AX.25: ax25_dg_build_path - out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		if (skb->sk != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			skb_set_owner_w(skbn, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		skb = skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	bp = skb_push(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	ax25_addr_build(bp, src, dest, digi, AX25_COMMAND, AX25_MODULUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  *	Free all memory associated with routing structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) void __exit ax25_rt_free(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	ax25_route *s, *ax25_rt = ax25_route_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	write_lock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	while (ax25_rt != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		s       = ax25_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		ax25_rt = ax25_rt->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		kfree(s->digipeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	write_unlock_bh(&ax25_route_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }