^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) #ifndef _NET_DN_ROUTE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _NET_DN_ROUTE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) (c) 1995-1998 E.M. Serrat emserrat@geocities.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) int dn_route_output_sock(struct dst_entry __rcu **pprt, struct flowidn *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct sock *sk, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) void dn_rt_cache_flush(int delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) int dn_route_rcv(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct packet_type *pt, struct net_device *orig_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Masks for flags field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DN_RT_F_PID 0x07 /* Mask for packet type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define DN_RT_F_PF 0x80 /* Padding Follows */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define DN_RT_F_VER 0x40 /* Version =0 discard packet if ==1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DN_RT_F_IE 0x20 /* Intra Ethernet, Reserved in short pkt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define DN_RT_F_RTS 0x10 /* Packet is being returned to sender */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DN_RT_F_RQR 0x08 /* Return packet to sender upon non-delivery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* Mask for types of routing packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define DN_RT_PKT_MSK 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* Types of routing packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define DN_RT_PKT_SHORT 0x02 /* Short routing packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define DN_RT_PKT_LONG 0x06 /* Long routing packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* Mask for control/routing selection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DN_RT_PKT_CNTL 0x01 /* Set to 1 if a control packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Types of control packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define DN_RT_CNTL_MSK 0x0f /* Mask for control packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define DN_RT_PKT_INIT 0x01 /* Initialisation packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define DN_RT_PKT_VERI 0x03 /* Verification Message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DN_RT_PKT_HELO 0x05 /* Hello and Test Message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define DN_RT_PKT_L1RT 0x07 /* Level 1 Routing Message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DN_RT_PKT_L2RT 0x09 /* Level 2 Routing Message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define DN_RT_PKT_ERTH 0x0b /* Ethernet Router Hello */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define DN_RT_PKT_EEDH 0x0d /* Ethernet EndNode Hello */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* Values for info field in hello message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define DN_RT_INFO_TYPE 0x03 /* Type mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define DN_RT_INFO_L1RT 0x02 /* L1 Router */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define DN_RT_INFO_L2RT 0x01 /* L2 Router */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define DN_RT_INFO_ENDN 0x03 /* EndNode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define DN_RT_INFO_VERI 0x04 /* Verification Reqd. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define DN_RT_INFO_RJCT 0x08 /* Reject Flag, Reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define DN_RT_INFO_VFLD 0x10 /* Verification Failed, Reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define DN_RT_INFO_NOML 0x20 /* No Multicast traffic accepted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define DN_RT_INFO_BLKR 0x40 /* Blocking Requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * The fl structure is what we used to look up the route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * The rt_saddr & rt_daddr entries are the same as key.saddr & key.daddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * except for local input routes, where the rt_saddr = fl.fld_dst and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * rt_daddr = fl.fld_src to allow the route to be used for returning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * packets to the originating host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct dn_route {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct dst_entry dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct dn_route __rcu *dn_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct neighbour *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct flowidn fld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __le16 rt_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) __le16 rt_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __le16 rt_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) __le16 rt_local_src; /* Source used for forwarding packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) __le16 rt_src_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) __le16 rt_dst_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned int rt_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned int rt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static inline bool dn_is_input_route(struct dn_route *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return rt->fld.flowidn_iif != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static inline bool dn_is_output_route(struct dn_route *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return rt->fld.flowidn_iif == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void dn_route_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) void dn_route_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static inline void dn_rt_send(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static inline void dn_rt_finish_output(struct sk_buff *skb, char *dst, char *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (dev_hard_header(skb, dev, ETH_P_DNA_RT, dst, src, skb->len) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) dn_rt_send(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #endif /* _NET_DN_ROUTE_H */