1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _NET_INET_IPX_H_
3*4882a593Smuzhiyun #define _NET_INET_IPX_H_
4*4882a593Smuzhiyun /*
5*4882a593Smuzhiyun * The following information is in its entirety obtained from:
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Novell 'IPX Router Specification' Version 1.10
8*4882a593Smuzhiyun * Part No. 107-000029-001
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Which is available from ftp.novell.com
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/netdevice.h>
14*4882a593Smuzhiyun #include <net/datalink.h>
15*4882a593Smuzhiyun #include <linux/ipx.h>
16*4882a593Smuzhiyun #include <linux/list.h>
17*4882a593Smuzhiyun #include <linux/slab.h>
18*4882a593Smuzhiyun #include <linux/refcount.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun struct ipx_address {
21*4882a593Smuzhiyun __be32 net;
22*4882a593Smuzhiyun __u8 node[IPX_NODE_LEN];
23*4882a593Smuzhiyun __be16 sock;
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #define ipx_broadcast_node "\377\377\377\377\377\377"
27*4882a593Smuzhiyun #define ipx_this_node "\0\0\0\0\0\0"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #define IPX_MAX_PPROP_HOPS 8
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun struct ipxhdr {
32*4882a593Smuzhiyun __be16 ipx_checksum __packed;
33*4882a593Smuzhiyun #define IPX_NO_CHECKSUM cpu_to_be16(0xFFFF)
34*4882a593Smuzhiyun __be16 ipx_pktsize __packed;
35*4882a593Smuzhiyun __u8 ipx_tctrl;
36*4882a593Smuzhiyun __u8 ipx_type;
37*4882a593Smuzhiyun #define IPX_TYPE_UNKNOWN 0x00
38*4882a593Smuzhiyun #define IPX_TYPE_RIP 0x01 /* may also be 0 */
39*4882a593Smuzhiyun #define IPX_TYPE_SAP 0x04 /* may also be 0 */
40*4882a593Smuzhiyun #define IPX_TYPE_SPX 0x05 /* SPX protocol */
41*4882a593Smuzhiyun #define IPX_TYPE_NCP 0x11 /* $lots for docs on this (SPIT) */
42*4882a593Smuzhiyun #define IPX_TYPE_PPROP 0x14 /* complicated flood fill brdcast */
43*4882a593Smuzhiyun struct ipx_address ipx_dest __packed;
44*4882a593Smuzhiyun struct ipx_address ipx_source __packed;
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /* From af_ipx.c */
48*4882a593Smuzhiyun extern int sysctl_ipx_pprop_broadcasting;
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun struct ipx_interface {
51*4882a593Smuzhiyun /* IPX address */
52*4882a593Smuzhiyun __be32 if_netnum;
53*4882a593Smuzhiyun unsigned char if_node[IPX_NODE_LEN];
54*4882a593Smuzhiyun refcount_t refcnt;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /* physical device info */
57*4882a593Smuzhiyun struct net_device *if_dev;
58*4882a593Smuzhiyun struct datalink_proto *if_dlink;
59*4882a593Smuzhiyun __be16 if_dlink_type;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun /* socket support */
62*4882a593Smuzhiyun unsigned short if_sknum;
63*4882a593Smuzhiyun struct hlist_head if_sklist;
64*4882a593Smuzhiyun spinlock_t if_sklist_lock;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun /* administrative overhead */
67*4882a593Smuzhiyun int if_ipx_offset;
68*4882a593Smuzhiyun unsigned char if_internal;
69*4882a593Smuzhiyun unsigned char if_primary;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun struct list_head node; /* node in ipx_interfaces list */
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun struct ipx_route {
75*4882a593Smuzhiyun __be32 ir_net;
76*4882a593Smuzhiyun struct ipx_interface *ir_intrfc;
77*4882a593Smuzhiyun unsigned char ir_routed;
78*4882a593Smuzhiyun unsigned char ir_router_node[IPX_NODE_LEN];
79*4882a593Smuzhiyun struct list_head node; /* node in ipx_routes list */
80*4882a593Smuzhiyun refcount_t refcnt;
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun struct ipx_cb {
84*4882a593Smuzhiyun u8 ipx_tctrl;
85*4882a593Smuzhiyun __be32 ipx_dest_net;
86*4882a593Smuzhiyun __be32 ipx_source_net;
87*4882a593Smuzhiyun struct {
88*4882a593Smuzhiyun __be32 netnum;
89*4882a593Smuzhiyun int index;
90*4882a593Smuzhiyun } last_hop;
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun #include <net/sock.h>
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun struct ipx_sock {
96*4882a593Smuzhiyun /* struct sock has to be the first member of ipx_sock */
97*4882a593Smuzhiyun struct sock sk;
98*4882a593Smuzhiyun struct ipx_address dest_addr;
99*4882a593Smuzhiyun struct ipx_interface *intrfc;
100*4882a593Smuzhiyun __be16 port;
101*4882a593Smuzhiyun #ifdef CONFIG_IPX_INTERN
102*4882a593Smuzhiyun unsigned char node[IPX_NODE_LEN];
103*4882a593Smuzhiyun #endif
104*4882a593Smuzhiyun unsigned short type;
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * To handle special ncp connection-handling sockets for mars_nwe,
107*4882a593Smuzhiyun * the connection number must be stored in the socket.
108*4882a593Smuzhiyun */
109*4882a593Smuzhiyun unsigned short ipx_ncp_conn;
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun
ipx_sk(struct sock * sk)112*4882a593Smuzhiyun static inline struct ipx_sock *ipx_sk(struct sock *sk)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun return (struct ipx_sock *)sk;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun #define IPX_SKB_CB(__skb) ((struct ipx_cb *)&((__skb)->cb[0]))
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun #define IPX_MIN_EPHEMERAL_SOCKET 0x4000
120*4882a593Smuzhiyun #define IPX_MAX_EPHEMERAL_SOCKET 0x7fff
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun extern struct list_head ipx_routes;
123*4882a593Smuzhiyun extern rwlock_t ipx_routes_lock;
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun extern struct list_head ipx_interfaces;
126*4882a593Smuzhiyun struct ipx_interface *ipx_interfaces_head(void);
127*4882a593Smuzhiyun extern spinlock_t ipx_interfaces_lock;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun extern struct ipx_interface *ipx_primary_net;
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun int ipx_proc_init(void);
132*4882a593Smuzhiyun void ipx_proc_exit(void);
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun const char *ipx_frame_name(__be16);
135*4882a593Smuzhiyun const char *ipx_device_name(struct ipx_interface *intrfc);
136*4882a593Smuzhiyun
ipxitf_hold(struct ipx_interface * intrfc)137*4882a593Smuzhiyun static __inline__ void ipxitf_hold(struct ipx_interface *intrfc)
138*4882a593Smuzhiyun {
139*4882a593Smuzhiyun refcount_inc(&intrfc->refcnt);
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun void ipxitf_down(struct ipx_interface *intrfc);
143*4882a593Smuzhiyun struct ipx_interface *ipxitf_find_using_net(__be32 net);
144*4882a593Smuzhiyun int ipxitf_send(struct ipx_interface *intrfc, struct sk_buff *skb, char *node);
145*4882a593Smuzhiyun __be16 ipx_cksum(struct ipxhdr *packet, int length);
146*4882a593Smuzhiyun int ipxrtr_add_route(__be32 network, struct ipx_interface *intrfc,
147*4882a593Smuzhiyun unsigned char *node);
148*4882a593Smuzhiyun void ipxrtr_del_routes(struct ipx_interface *intrfc);
149*4882a593Smuzhiyun int ipxrtr_route_packet(struct sock *sk, struct sockaddr_ipx *usipx,
150*4882a593Smuzhiyun struct msghdr *msg, size_t len, int noblock);
151*4882a593Smuzhiyun int ipxrtr_route_skb(struct sk_buff *skb);
152*4882a593Smuzhiyun struct ipx_route *ipxrtr_lookup(__be32 net);
153*4882a593Smuzhiyun int ipxrtr_ioctl(unsigned int cmd, void __user *arg);
154*4882a593Smuzhiyun
ipxitf_put(struct ipx_interface * intrfc)155*4882a593Smuzhiyun static __inline__ void ipxitf_put(struct ipx_interface *intrfc)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun if (refcount_dec_and_test(&intrfc->refcnt))
158*4882a593Smuzhiyun ipxitf_down(intrfc);
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun
ipxrtr_hold(struct ipx_route * rt)161*4882a593Smuzhiyun static __inline__ void ipxrtr_hold(struct ipx_route *rt)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun refcount_inc(&rt->refcnt);
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun
ipxrtr_put(struct ipx_route * rt)166*4882a593Smuzhiyun static __inline__ void ipxrtr_put(struct ipx_route *rt)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun if (refcount_dec_and_test(&rt->refcnt))
169*4882a593Smuzhiyun kfree(rt);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun #endif /* _NET_INET_IPX_H_ */
172