Lines Matching +full:route +full:- +full:ptp
1 // SPDX-License-Identifier: GPL-2.0-or-later
29 * Bradford Johnson : IP-over-DDP (experimental)
30 * Jay Schulist : Moved IP-over-DDP to its own
59 #include <net/route.h>
98 if (to->sat_port != at->src_port) in atalk_search_socket()
101 if (to->sat_addr.s_net == ATADDR_ANYNET && in atalk_search_socket()
102 to->sat_addr.s_node == ATADDR_BCAST) { in atalk_search_socket()
103 if (atif->address.s_node == at->src_node && in atalk_search_socket()
104 atif->address.s_net == at->src_net) { in atalk_search_socket()
106 * that received the packet -- use it in atalk_search_socket()
117 if (to->sat_addr.s_net == at->src_net && in atalk_search_socket()
118 (to->sat_addr.s_node == at->src_node || in atalk_search_socket()
119 to->sat_addr.s_node == ATADDR_BCAST || in atalk_search_socket()
120 to->sat_addr.s_node == ATADDR_ANYNODE)) in atalk_search_socket()
123 /* XXXX.0 -- we got a request for this router. make sure in atalk_search_socket()
125 if (to->sat_addr.s_node == ATADDR_ANYNODE && in atalk_search_socket()
126 to->sat_addr.s_net != ATADDR_ANYNET && in atalk_search_socket()
127 atif->address.s_node == at->src_node) { in atalk_search_socket()
128 to->sat_addr.s_node = atif->address.s_node; in atalk_search_socket()
139 * atalk_find_or_insert_socket - Try to find a socket matching ADDR
158 if (at->src_net == sat->sat_addr.s_net && in atalk_find_or_insert_socket()
159 at->src_node == sat->sat_addr.s_node && in atalk_find_or_insert_socket()
160 at->src_port == sat->sat_port) in atalk_find_or_insert_socket()
175 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME; in atalk_destroy_timer()
176 add_timer(&sk->sk_timer); in atalk_destroy_timer()
184 skb_queue_purge(&sk->sk_receive_queue); in atalk_destroy_socket()
187 timer_setup(&sk->sk_timer, atalk_destroy_timer, 0); in atalk_destroy_socket()
188 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME; in atalk_destroy_socket()
189 add_timer(&sk->sk_timer); in atalk_destroy_socket()
200 /* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
212 * Drop a device. Doesn't drop any of its routes - that is the caller's
222 if (tmp->dev == dev) { in atif_drop_device()
223 *iface = tmp->next; in atif_drop_device()
226 dev->atalk_ptr = NULL; in atif_drop_device()
228 iface = &tmp->next; in atif_drop_device()
242 iface->dev = dev; in atif_add_device()
243 dev->atalk_ptr = iface; in atif_add_device()
244 iface->address = *sa; in atif_add_device()
245 iface->status = 0; in atif_add_device()
248 iface->next = atalk_interfaces; in atif_add_device()
258 int netrange = ntohs(atif->nets.nr_lastnet) - in atif_probe_device()
259 ntohs(atif->nets.nr_firstnet) + 1; in atif_probe_device()
260 int probe_net = ntohs(atif->address.s_net); in atif_probe_device()
261 int probe_node = atif->address.s_node; in atif_probe_device()
266 probe_net = ntohs(atif->nets.nr_firstnet); in atif_probe_device()
274 atif->status |= ATIF_PROBE; in atif_probe_device()
277 atif->address.s_net = htons(probe_net); in atif_probe_device()
279 atif->address.s_node = (nodect + probe_node) & 0xFF; in atif_probe_device()
280 if (atif->address.s_node > 0 && in atif_probe_device()
281 atif->address.s_node < 254) { in atif_probe_device()
285 if (!(atif->status & ATIF_PROBE_FAIL)) { in atif_probe_device()
286 atif->status &= ~ATIF_PROBE; in atif_probe_device()
290 atif->status &= ~ATIF_PROBE_FAIL; in atif_probe_device()
293 if (probe_net > ntohs(atif->nets.nr_lastnet)) in atif_probe_device()
294 probe_net = ntohs(atif->nets.nr_firstnet); in atif_probe_device()
296 atif->status &= ~ATIF_PROBE; in atif_probe_device()
298 return -EADDRINUSE; /* Network is full... */ in atif_probe_device()
306 int netrange = ntohs(atif->nets.nr_lastnet) - in atif_proxy_probe_device()
307 ntohs(atif->nets.nr_firstnet) + 1; in atif_proxy_probe_device()
309 int probe_net = ntohs(atif->address.s_net); in atif_proxy_probe_device()
315 probe_net = ntohs(atif->nets.nr_firstnet); in atif_proxy_probe_device()
326 proxy_addr->s_net = htons(probe_net); in atif_proxy_probe_device()
328 proxy_addr->s_node = (nodect + probe_node) & 0xFF; in atif_proxy_probe_device()
329 if (proxy_addr->s_node > 0 && in atif_proxy_probe_device()
330 proxy_addr->s_node < 254) { in atif_proxy_probe_device()
335 if (ret != -EADDRINUSE) in atif_proxy_probe_device()
340 if (probe_net > ntohs(atif->nets.nr_lastnet)) in atif_proxy_probe_device()
341 probe_net = ntohs(atif->nets.nr_firstnet); in atif_proxy_probe_device()
344 return -EADDRINUSE; /* Network is full... */ in atif_proxy_probe_device()
350 struct atalk_iface *iface = dev->atalk_ptr; in atalk_find_dev_addr()
351 return iface ? &iface->address : NULL; in atalk_find_dev_addr()
361 * Return a point-to-point interface only if in atalk_find_primary()
362 * there is no non-ptp interface available. in atalk_find_primary()
365 for (iface = atalk_interfaces; iface; iface = iface->next) { in atalk_find_primary()
366 if (!fiface && !(iface->dev->flags & IFF_LOOPBACK)) in atalk_find_primary()
368 if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) { in atalk_find_primary()
369 retval = &iface->address; in atalk_find_primary()
375 retval = &fiface->address; in atalk_find_primary()
377 retval = &atalk_interfaces->address; in atalk_find_primary()
386 * Find a match for 'any network' - ie any of our interfaces with that
391 struct atalk_iface *iface = dev->atalk_ptr; in atalk_find_anynet()
393 if (!iface || iface->status & ATIF_PROBE) in atalk_find_anynet()
397 iface->address.s_node != node && in atalk_find_anynet()
413 for (iface = atalk_interfaces; iface; iface = iface->next) { in atalk_find_interface()
416 iface->address.s_node == node) && in atalk_find_interface()
417 iface->address.s_net == net && in atalk_find_interface()
418 !(iface->status & ATIF_PROBE)) in atalk_find_interface()
421 /* XXXX.0 -- net.0 returns the iface associated with net */ in atalk_find_interface()
423 ntohs(iface->nets.nr_firstnet) <= ntohs(net) && in atalk_find_interface()
424 ntohs(net) <= ntohs(iface->nets.nr_lastnet)) in atalk_find_interface()
433 * Find a route for an AppleTalk packet. This ought to get cached in
435 * that a route must be direct to broadcast.
441 * host route, because some host routes might overlap in atrtr_find()
448 for (r = atalk_routes; r; r = r->next) { in atrtr_find()
449 if (!(r->flags & RTF_UP)) in atrtr_find()
452 if (r->target.s_net == target->s_net) { in atrtr_find()
453 if (r->flags & RTF_HOST) { in atrtr_find()
455 * if this host route is for the target, in atrtr_find()
458 if (r->target.s_node == target->s_node) in atrtr_find()
462 * this route will work if there isn't a in atrtr_find()
463 * direct host route, so cache it in atrtr_find()
470 * if we found a network route but not a direct host in atrtr_find()
471 * route, then return it in atrtr_find()
477 else /* No route can be found */ in atrtr_find()
492 return atr ? atr->dev : NULL; in atrtr_get_dev()
511 struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst; in atrtr_create()
512 struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway; in atrtr_create()
515 int retval = -EINVAL; in atrtr_create()
523 if (ta->sat_family != AF_APPLETALK || in atrtr_create()
524 (!devhint && ga->sat_family != AF_APPLETALK)) in atrtr_create()
529 for (rt = atalk_routes; rt; rt = rt->next) { in atrtr_create()
530 if (r->rt_flags != rt->flags) in atrtr_create()
533 if (ta->sat_addr.s_net == rt->target.s_net) { in atrtr_create()
534 if (!(rt->flags & RTF_HOST)) in atrtr_create()
536 if (ta->sat_addr.s_node == rt->target.s_node) in atrtr_create()
545 for (iface = atalk_interfaces; iface; iface = iface->next) { in atrtr_create()
547 ntohs(ga->sat_addr.s_net) >= in atrtr_create()
548 ntohs(iface->nets.nr_firstnet) && in atrtr_create()
549 ntohs(ga->sat_addr.s_net) <= in atrtr_create()
550 ntohs(iface->nets.nr_lastnet)) in atrtr_create()
553 if (ga->sat_addr.s_net == iface->address.s_net && in atrtr_create()
554 ga->sat_addr.s_node == iface->address.s_node) in atrtr_create()
559 retval = -ENETUNREACH; in atrtr_create()
563 devhint = riface->dev; in atrtr_create()
569 retval = -ENOBUFS; in atrtr_create()
573 rt->next = atalk_routes; in atrtr_create()
578 rt->target = ta->sat_addr; in atrtr_create()
580 rt->dev = devhint; in atrtr_create()
581 rt->flags = r->rt_flags; in atrtr_create()
582 rt->gateway = ga->sat_addr; in atrtr_create()
591 /* Delete a route. Find it and discard it */
600 if (tmp->target.s_net == addr->s_net && in atrtr_delete()
601 (!(tmp->flags&RTF_GATEWAY) || in atrtr_delete()
602 tmp->target.s_node == addr->s_node)) { in atrtr_delete()
603 *r = tmp->next; in atrtr_delete()
604 dev_put(tmp->dev); in atrtr_delete()
608 r = &tmp->next; in atrtr_delete()
610 retval = -ENOENT; in atrtr_delete()
627 if (tmp->dev == dev) { in atrtr_device_down()
628 *r = tmp->next; in atrtr_device_down()
632 r = &tmp->next; in atrtr_device_down()
650 * delete our use of them (iface and route).
683 return -EFAULT; in atif_ioctl()
687 return -ENODEV; in atif_ioctl()
695 return -EPERM; in atif_ioctl()
696 if (sa->sat_family != AF_APPLETALK) in atif_ioctl()
697 return -EINVAL; in atif_ioctl()
698 if (dev->type != ARPHRD_ETHER && in atif_ioctl()
699 dev->type != ARPHRD_LOOPBACK && in atif_ioctl()
700 dev->type != ARPHRD_LOCALTLK && in atif_ioctl()
701 dev->type != ARPHRD_PPP) in atif_ioctl()
702 return -EPROTONOSUPPORT; in atif_ioctl()
704 nr = (struct atalk_netrange *)&sa->sat_zero[0]; in atif_ioctl()
708 * if this is a point-to-point iface, and we already in atif_ioctl()
710 * should not add a route in atif_ioctl()
712 if ((dev->flags & IFF_POINTOPOINT) && in atif_ioctl()
713 atalk_find_interface(sa->sat_addr.s_net, in atif_ioctl()
714 sa->sat_addr.s_node)) { in atif_ioctl()
715 printk(KERN_DEBUG "AppleTalk: point-to-point " in atif_ioctl()
725 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2) in atif_ioctl()
726 return -EPROTONOSUPPORT; in atif_ioctl()
727 if (sa->sat_addr.s_node == ATADDR_BCAST || in atif_ioctl()
728 sa->sat_addr.s_node == 254) in atif_ioctl()
729 return -EINVAL; in atif_ioctl()
732 if (atif->status & ATIF_PROBE) in atif_ioctl()
733 return -EBUSY; in atif_ioctl()
735 atif->address.s_net = sa->sat_addr.s_net; in atif_ioctl()
736 atif->address.s_node = sa->sat_addr.s_node; in atif_ioctl()
739 atif = atif_add_device(dev, &sa->sat_addr); in atif_ioctl()
741 return -ENOMEM; in atif_ioctl()
743 atif->nets = *nr; in atif_ioctl()
750 if (!(dev->flags & IFF_LOOPBACK) && in atif_ioctl()
751 !(dev->flags & IFF_POINTOPOINT) && in atif_ioctl()
754 return -EADDRINUSE; in atif_ioctl()
757 /* Hey it worked - add the direct routes */ in atif_ioctl()
759 sa->sat_family = AF_APPLETALK; in atif_ioctl()
760 sa->sat_addr.s_net = atif->address.s_net; in atif_ioctl()
761 sa->sat_addr.s_node = atif->address.s_node; in atif_ioctl()
764 sa->sat_family = AF_APPLETALK; in atif_ioctl()
765 sa->sat_addr.s_node = ATADDR_ANYNODE; in atif_ioctl()
766 if (dev->flags & IFF_LOOPBACK || in atif_ioctl()
767 dev->flags & IFF_POINTOPOINT) in atif_ioctl()
771 if (nr->nr_firstnet == htons(0) && in atif_ioctl()
772 nr->nr_lastnet == htons(0xFFFE)) { in atif_ioctl()
773 sa->sat_addr.s_net = atif->address.s_net; in atif_ioctl()
777 limit = ntohs(nr->nr_lastnet); in atif_ioctl()
778 if (limit - ntohs(nr->nr_firstnet) > 4096) { in atif_ioctl()
781 return -EINVAL; in atif_ioctl()
784 for (ct = ntohs(nr->nr_firstnet); in atif_ioctl()
786 sa->sat_addr.s_net = htons(ct); in atif_ioctl()
795 return -EADDRNOTAVAIL; in atif_ioctl()
797 sa->sat_family = AF_APPLETALK; in atif_ioctl()
798 sa->sat_addr = atif->address; in atif_ioctl()
803 return -EADDRNOTAVAIL; in atif_ioctl()
805 sa->sat_family = AF_APPLETALK; in atif_ioctl()
806 sa->sat_addr.s_net = atif->address.s_net; in atif_ioctl()
807 sa->sat_addr.s_node = ATADDR_BCAST; in atif_ioctl()
813 return -EPERM; in atif_ioctl()
814 if (sa->sat_family != AF_APPLETALK) in atif_ioctl()
815 return -EINVAL; in atif_ioctl()
821 return -EPERM; in atif_ioctl()
822 if (sa->sat_family != AF_APPLETALK) in atif_ioctl()
823 return -EINVAL; in atif_ioctl()
828 if (dev->type != ARPHRD_ETHER) in atif_ioctl()
829 return -EPROTONOSUPPORT; in atif_ioctl()
839 return -EADDRNOTAVAIL; in atif_ioctl()
841 nr = (struct atalk_netrange *)&(atif->nets); in atif_ioctl()
846 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2) in atif_ioctl()
847 return -EPROTONOSUPPORT; in atif_ioctl()
849 if (sa->sat_addr.s_node == ATADDR_BCAST || in atif_ioctl()
850 sa->sat_addr.s_node == 254) in atif_ioctl()
851 return -EINVAL; in atif_ioctl()
857 if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0) in atif_ioctl()
858 return -EADDRINUSE; in atif_ioctl()
870 return -EPERM; in atif_ioctl()
871 if (sa->sat_family != AF_APPLETALK) in atif_ioctl()
872 return -EINVAL; in atif_ioctl()
874 return -EADDRNOTAVAIL; in atif_ioctl()
877 aarp_proxy_remove(atif->dev, &(sa->sat_addr)); in atif_ioctl()
888 if (rt->rt_dev) { in atrtr_ioctl_addrt()
891 if (copy_from_user(name, rt->rt_dev, IFNAMSIZ-1)) in atrtr_ioctl_addrt()
892 return -EFAULT; in atrtr_ioctl_addrt()
893 name[IFNAMSIZ-1] = '\0'; in atrtr_ioctl_addrt()
897 return -ENODEV; in atrtr_ioctl_addrt()
908 return -EFAULT; in atrtr_ioctl()
913 return -EINVAL; in atrtr_ioctl()
915 &rt.rt_dst)->sat_addr); in atrtr_ioctl()
920 return -EINVAL; in atrtr_ioctl()
938 while (len--) { in atalk_sum_partial()
945 /* Checksum skb data -- similar to skb_checksum */
954 if ((copy = start - offset) > 0) { in atalk_sum_skb()
957 sum = atalk_sum_partial(skb->data + offset, copy, sum); in atalk_sum_skb()
958 if ((len -= copy) == 0) in atalk_sum_skb()
965 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in atalk_sum_skb()
967 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in atalk_sum_skb()
971 if ((copy = end - offset) > 0) { in atalk_sum_skb()
978 offset - start, copy, sum); in atalk_sum_skb()
981 if (!(len -= copy)) in atalk_sum_skb()
993 end = start + frag_iter->len; in atalk_sum_skb()
994 if ((copy = end - offset) > 0) { in atalk_sum_skb()
997 sum = atalk_sum_skb(frag_iter, offset - start, in atalk_sum_skb()
999 if ((len -= copy) == 0) in atalk_sum_skb()
1016 sum = atalk_sum_skb(skb, 4, len-4, 0); in atalk_checksum()
1036 int rc = -ESOCKTNOSUPPORT; in atalk_create()
1039 return -EAFNOSUPPORT; in atalk_create()
1045 if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM) in atalk_create()
1048 rc = -EPERM; in atalk_create()
1049 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW)) in atalk_create()
1052 rc = -ENOMEM; in atalk_create()
1057 sock->ops = &atalk_dgram_ops; in atalk_create()
1069 struct sock *sk = sock->sk; in atalk_release()
1076 sock->sk = NULL; in atalk_release()
1086 * atalk_pick_and_bind_port - Pick a source port when one is not given
1101 for (sat->sat_port = ATPORT_RESERVED; in atalk_pick_and_bind_port()
1102 sat->sat_port < ATPORT_LAST; in atalk_pick_and_bind_port()
1103 sat->sat_port++) { in atalk_pick_and_bind_port()
1109 if (at->src_net == sat->sat_addr.s_net && in atalk_pick_and_bind_port()
1110 at->src_node == sat->sat_addr.s_node && in atalk_pick_and_bind_port()
1111 at->src_port == sat->sat_port) in atalk_pick_and_bind_port()
1117 at_sk(sk)->src_port = sat->sat_port; in atalk_pick_and_bind_port()
1124 retval = -EBUSY; in atalk_pick_and_bind_port()
1135 int n = -EADDRNOTAVAIL; in atalk_autobind()
1137 if (!ap || ap->s_net == htons(ATADDR_ANYNET)) in atalk_autobind()
1140 at->src_net = sat.sat_addr.s_net = ap->s_net; in atalk_autobind()
1141 at->src_node = sat.sat_addr.s_node = ap->s_node; in atalk_autobind()
1154 struct sock *sk = sock->sk; in atalk_bind()
1160 return -EINVAL; in atalk_bind()
1162 if (addr->sat_family != AF_APPLETALK) in atalk_bind()
1163 return -EAFNOSUPPORT; in atalk_bind()
1166 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) { in atalk_bind()
1169 err = -EADDRNOTAVAIL; in atalk_bind()
1173 at->src_net = addr->sat_addr.s_net = ap->s_net; in atalk_bind()
1174 at->src_node = addr->sat_addr.s_node = ap->s_node; in atalk_bind()
1176 err = -EADDRNOTAVAIL; in atalk_bind()
1177 if (!atalk_find_interface(addr->sat_addr.s_net, in atalk_bind()
1178 addr->sat_addr.s_node)) in atalk_bind()
1181 at->src_net = addr->sat_addr.s_net; in atalk_bind()
1182 at->src_node = addr->sat_addr.s_node; in atalk_bind()
1185 if (addr->sat_port == ATADDR_ANYPORT) { in atalk_bind()
1191 at->src_port = addr->sat_port; in atalk_bind()
1193 err = -EADDRINUSE; in atalk_bind()
1209 struct sock *sk = sock->sk; in atalk_connect()
1214 sk->sk_state = TCP_CLOSE; in atalk_connect()
1215 sock->state = SS_UNCONNECTED; in atalk_connect()
1218 return -EINVAL; in atalk_connect()
1222 if (addr->sat_family != AF_APPLETALK) in atalk_connect()
1223 return -EAFNOSUPPORT; in atalk_connect()
1225 if (addr->sat_addr.s_node == ATADDR_BCAST && in atalk_connect()
1229 current->comm); in atalk_connect()
1231 return -EACCES; in atalk_connect()
1236 err = -EBUSY; in atalk_connect()
1241 err = -ENETUNREACH; in atalk_connect()
1242 if (!atrtr_get_dev(&addr->sat_addr)) in atalk_connect()
1245 at->dest_port = addr->sat_port; in atalk_connect()
1246 at->dest_net = addr->sat_addr.s_net; in atalk_connect()
1247 at->dest_node = addr->sat_addr.s_node; in atalk_connect()
1249 sock->state = SS_CONNECTED; in atalk_connect()
1250 sk->sk_state = TCP_ESTABLISHED; in atalk_connect()
1265 struct sock *sk = sock->sk; in atalk_getname()
1270 err = -ENOBUFS; in atalk_getname()
1278 err = -ENOTCONN; in atalk_getname()
1279 if (sk->sk_state != TCP_ESTABLISHED) in atalk_getname()
1282 sat.sat_addr.s_net = at->dest_net; in atalk_getname()
1283 sat.sat_addr.s_node = at->dest_node; in atalk_getname()
1284 sat.sat_port = at->dest_port; in atalk_getname()
1286 sat.sat_addr.s_net = at->src_net; in atalk_getname()
1287 sat.sat_addr.s_node = at->src_node; in atalk_getname()
1288 sat.sat_port = at->src_port; in atalk_getname()
1307 * Don't route multicast, etc., packets, or packets sent to "this in atalk_route_packet()
1310 if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) { in atalk_route_packet()
1317 if (dev->type == ARPHRD_PPP) in atalk_route_packet()
1323 ta.s_net = ddp->deh_dnet; in atalk_route_packet()
1324 ta.s_node = ddp->deh_dnode; in atalk_route_packet()
1326 /* Route the packet */ in atalk_route_packet()
1333 /* FIXME: use skb->cb to be able to use shared skbs */ in atalk_route_packet()
1336 * Route goes through another gateway, so set the target to the in atalk_route_packet()
1340 if (rt->flags & RTF_GATEWAY) { in atalk_route_packet()
1341 ta.s_net = rt->gateway.s_net; in atalk_route_packet()
1342 ta.s_node = rt->gateway.s_node; in atalk_route_packet()
1345 /* Fix up skb->len field */ in atalk_route_packet()
1347 (rt->dev->hard_header_len + in atalk_route_packet()
1348 ddp_dl->header_length + (len_hops & 1023)))); in atalk_route_packet()
1350 /* FIXME: use skb->cb to be able to use shared skbs */ in atalk_route_packet()
1351 ddp->deh_len_hops = htons(len_hops); in atalk_route_packet()
1362 * Note. ddp-> becomes invalid at the realloc. in atalk_route_packet()
1365 /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */ in atalk_route_packet()
1379 if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP) in atalk_route_packet()
1389 * atalk_rcv - Receive a packet (in skb) from device dev
1396 * decoder, and on entry skb->transport_header is the DDP header, skb->len
1397 * is the DDP header, skb->len is the DDP length. The physical headers
1424 len_hops = ntohs(ddp->deh_len_hops); in atalk_rcv()
1427 origlen = skb->len; in atalk_rcv()
1428 skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023)); in atalk_rcv()
1431 * Size check to see if ddp->deh_len was crap in atalk_rcv()
1435 if (skb->len < sizeof(*ddp) || skb->len < (len_hops & 1023)) { in atalk_rcv()
1437 "skb->len=%u)\n", len_hops & 1023, skb->len); in atalk_rcv()
1445 if (ddp->deh_sum && in atalk_rcv()
1446 atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum) in atalk_rcv()
1447 /* Not a valid AppleTalk frame - dustbin time */ in atalk_rcv()
1451 if (!ddp->deh_dnet) /* Net 0 is 'this network' */ in atalk_rcv()
1452 atif = atalk_find_anynet(ddp->deh_dnode, dev); in atalk_rcv()
1454 atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode); in atalk_rcv()
1457 /* Not ours, so we route the packet via the correct in atalk_rcv()
1464 * Which socket - atalk_search_socket() looks for a *full match* in atalk_rcv()
1467 tosat.sat_addr.s_net = ddp->deh_dnet; in atalk_rcv()
1468 tosat.sat_addr.s_node = ddp->deh_dnode; in atalk_rcv()
1469 tosat.sat_port = ddp->deh_dport; in atalk_rcv()
1505 if (!ap || skb->len < sizeof(__be16) || skb->len > 1023) in ltalk_rcv()
1516 ddp = skb_push(skb, sizeof(*ddp) - 4); in ltalk_rcv()
1526 ddp->deh_dnode = skb_mac_header(skb)[0]; /* From physical header */ in ltalk_rcv()
1527 ddp->deh_snode = skb_mac_header(skb)[1]; /* From physical header */ in ltalk_rcv()
1529 ddp->deh_dnet = ap->s_net; /* Network number */ in ltalk_rcv()
1530 ddp->deh_snet = ap->s_net; in ltalk_rcv()
1531 ddp->deh_sum = 0; /* No checksum */ in ltalk_rcv()
1536 ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10)); in ltalk_rcv()
1548 struct sock *sk = sock->sk; in atalk_sendmsg()
1550 DECLARE_SOCKADDR(struct sockaddr_at *, usat, msg->msg_name); in atalk_sendmsg()
1551 int flags = msg->msg_flags; in atalk_sendmsg()
1562 return -EINVAL; in atalk_sendmsg()
1565 return -EMSGSIZE; in atalk_sendmsg()
1569 err = -EBUSY; in atalk_sendmsg()
1574 err = -EINVAL; in atalk_sendmsg()
1575 if (msg->msg_namelen < sizeof(*usat) || in atalk_sendmsg()
1576 usat->sat_family != AF_APPLETALK) in atalk_sendmsg()
1579 err = -EPERM; in atalk_sendmsg()
1581 if (usat->sat_addr.s_node == ATADDR_BCAST && in atalk_sendmsg()
1586 err = -ENOTCONN; in atalk_sendmsg()
1587 if (sk->sk_state != TCP_ESTABLISHED) in atalk_sendmsg()
1590 usat->sat_family = AF_APPLETALK; in atalk_sendmsg()
1591 usat->sat_port = at->dest_port; in atalk_sendmsg()
1592 usat->sat_addr.s_node = at->dest_node; in atalk_sendmsg()
1593 usat->sat_addr.s_net = at->dest_net; in atalk_sendmsg()
1600 size = sizeof(struct ddpehdr) + len + ddp_dl->header_length; in atalk_sendmsg()
1602 if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) { in atalk_sendmsg()
1603 rt = atrtr_find(&usat->sat_addr); in atalk_sendmsg()
1608 at_hint.s_net = at->src_net; in atalk_sendmsg()
1612 err = -ENETUNREACH; in atalk_sendmsg()
1616 dev = rt->dev; in atalk_sendmsg()
1619 sk, size, dev->name); in atalk_sendmsg()
1621 hard_header_len = dev->hard_header_len; in atalk_sendmsg()
1623 if (usat->sat_addr.s_node == ATADDR_BCAST && in atalk_sendmsg()
1624 (dev->flags & IFF_LOOPBACK || !(rt->flags & RTF_GATEWAY))) { in atalk_sendmsg()
1632 if (rt_lo && rt_lo->dev->hard_header_len > hard_header_len) in atalk_sendmsg()
1633 hard_header_len = rt_lo->dev->hard_header_len; in atalk_sendmsg()
1643 skb_reserve(skb, ddp_dl->header_length); in atalk_sendmsg()
1645 skb->dev = dev; in atalk_sendmsg()
1650 ddp->deh_len_hops = htons(len + sizeof(*ddp)); in atalk_sendmsg()
1651 ddp->deh_dnet = usat->sat_addr.s_net; in atalk_sendmsg()
1652 ddp->deh_snet = at->src_net; in atalk_sendmsg()
1653 ddp->deh_dnode = usat->sat_addr.s_node; in atalk_sendmsg()
1654 ddp->deh_snode = at->src_node; in atalk_sendmsg()
1655 ddp->deh_dport = usat->sat_port; in atalk_sendmsg()
1656 ddp->deh_sport = at->src_port; in atalk_sendmsg()
1663 err = -EFAULT; in atalk_sendmsg()
1667 if (sk->sk_no_check_tx) in atalk_sendmsg()
1668 ddp->deh_sum = 0; in atalk_sendmsg()
1670 ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp)); in atalk_sendmsg()
1676 if (ddp->deh_dnode == ATADDR_BCAST && in atalk_sendmsg()
1677 !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) { in atalk_sendmsg()
1686 aarp_send_ddp(dev, skb2, &usat->sat_addr, NULL); in atalk_sendmsg()
1690 if (dev->flags & IFF_LOOPBACK || loopback) { in atalk_sendmsg()
1694 if (ddp->deh_dnode == ATADDR_BCAST) { in atalk_sendmsg()
1697 err = -ENETUNREACH; in atalk_sendmsg()
1700 dev = rt_lo->dev; in atalk_sendmsg()
1701 skb->dev = dev; in atalk_sendmsg()
1703 ddp_dl->request(ddp_dl, skb, dev->dev_addr); in atalk_sendmsg()
1706 if (rt->flags & RTF_GATEWAY) { in atalk_sendmsg()
1707 gsat.sat_addr = rt->gateway; in atalk_sendmsg()
1714 aarp_send_ddp(dev, skb, &usat->sat_addr, NULL); in atalk_sendmsg()
1726 struct sock *sk = sock->sk; in atalk_recvmsg()
1739 /* FIXME: use skb->cb to be able to use shared skbs */ in atalk_recvmsg()
1741 copied = ntohs(ddp->deh_len_hops) & 1023; in atalk_recvmsg()
1743 if (sk->sk_type != SOCK_RAW) { in atalk_recvmsg()
1745 copied -= offset; in atalk_recvmsg()
1750 msg->msg_flags |= MSG_TRUNC; in atalk_recvmsg()
1754 if (!err && msg->msg_name) { in atalk_recvmsg()
1755 DECLARE_SOCKADDR(struct sockaddr_at *, sat, msg->msg_name); in atalk_recvmsg()
1756 sat->sat_family = AF_APPLETALK; in atalk_recvmsg()
1757 sat->sat_port = ddp->deh_sport; in atalk_recvmsg()
1758 sat->sat_addr.s_node = ddp->deh_snode; in atalk_recvmsg()
1759 sat->sat_addr.s_net = ddp->deh_snet; in atalk_recvmsg()
1760 msg->msg_namelen = sizeof(*sat); in atalk_recvmsg()
1776 int rc = -ENOIOCTLCMD; in atalk_ioctl()
1777 struct sock *sk = sock->sk; in atalk_ioctl()
1783 long amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk); in atalk_ioctl()
1794 spin_lock_irq(&sk->sk_receive_queue.lock); in atalk_ioctl()
1795 skb = skb_peek(&sk->sk_receive_queue); in atalk_ioctl()
1797 amount = skb->len - sizeof(struct ddpehdr); in atalk_ioctl()
1798 spin_unlock_irq(&sk->sk_receive_queue.lock); in atalk_ioctl()
1805 rc = -EPERM; in atalk_ioctl()
1834 if (copy_from_user(&rt.rt_dst, &ur->rt_dst, in atalk_compat_routing_ioctl()
1836 get_user(rt.rt_flags, &ur->rt_flags) || in atalk_compat_routing_ioctl()
1837 get_user(rt.rt_metric, &ur->rt_metric) || in atalk_compat_routing_ioctl()
1838 get_user(rt.rt_mtu, &ur->rt_mtu) || in atalk_compat_routing_ioctl()
1839 get_user(rt.rt_window, &ur->rt_window) || in atalk_compat_routing_ioctl()
1840 get_user(rt.rt_irtt, &ur->rt_irtt) || in atalk_compat_routing_ioctl()
1841 get_user(rtdev, &ur->rt_dev)) in atalk_compat_routing_ioctl()
1842 return -EFAULT; in atalk_compat_routing_ioctl()
1847 return -EINVAL; in atalk_compat_routing_ioctl()
1849 &rt.rt_dst)->sat_addr); in atalk_compat_routing_ioctl()
1855 return -EINVAL; in atalk_compat_routing_ioctl()
1861 struct sock *sk = sock->sk; in atalk_compat_ioctl()
1876 return -ENOIOCTLCMD; in atalk_compat_ioctl()
1946 rc = -ENOMEM; in atalk_init()
2003 aarp_cleanup_module(); /* General aarp clean-up. */ in atalk_exit()