blob: baf0903909984de0a2ee823f72e3cd673da42961 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _NET_INET_IPX_H_
3#define _NET_INET_IPX_H_
4/*
5 * The following information is in its entirety obtained from:
6 *
7 * Novell 'IPX Router Specification' Version 1.10
8 * Part No. 107-000029-001
9 *
10 * Which is available from ftp.novell.com
11 */
12
13#include <linux/netdevice.h>
14#include <net/datalink.h>
15#include <linux/ipx.h>
16#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Reshetova, Elenad25189c2017-07-04 15:53:09 +030018#include <linux/refcount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20struct ipx_address {
Al Viro4833ed02006-11-03 00:27:06 -080021 __be32 net;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 __u8 node[IPX_NODE_LEN];
Al Viro4833ed02006-11-03 00:27:06 -080023 __be16 sock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024};
25
26#define ipx_broadcast_node "\377\377\377\377\377\377"
27#define ipx_this_node "\0\0\0\0\0\0"
28
29#define IPX_MAX_PPROP_HOPS 8
30
31struct ipxhdr {
Eric Dumazetbc105022010-06-03 03:21:52 -070032 __be16 ipx_checksum __packed;
Harvey Harrisonf3a7c662009-02-14 22:58:35 -080033#define IPX_NO_CHECKSUM cpu_to_be16(0xFFFF)
Eric Dumazetbc105022010-06-03 03:21:52 -070034 __be16 ipx_pktsize __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 __u8 ipx_tctrl;
36 __u8 ipx_type;
37#define IPX_TYPE_UNKNOWN 0x00
38#define IPX_TYPE_RIP 0x01 /* may also be 0 */
39#define IPX_TYPE_SAP 0x04 /* may also be 0 */
40#define IPX_TYPE_SPX 0x05 /* SPX protocol */
41#define IPX_TYPE_NCP 0x11 /* $lots for docs on this (SPIT) */
42#define IPX_TYPE_PPROP 0x14 /* complicated flood fill brdcast */
Eric Dumazetbc105022010-06-03 03:21:52 -070043 struct ipx_address ipx_dest __packed;
44 struct ipx_address ipx_source __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
Fabian Frederick5e96d782014-10-27 20:00:41 +010047/* From af_ipx.c */
48extern int sysctl_ipx_pprop_broadcasting;
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static __inline__ struct ipxhdr *ipx_hdr(struct sk_buff *skb)
51{
Arnaldo Carvalho de Melo9c702202007-04-25 18:04:18 -070052 return (struct ipxhdr *)skb_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55struct ipx_interface {
56 /* IPX address */
Al Viro4833ed02006-11-03 00:27:06 -080057 __be32 if_netnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 unsigned char if_node[IPX_NODE_LEN];
Reshetova, Elenad25189c2017-07-04 15:53:09 +030059 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 /* physical device info */
62 struct net_device *if_dev;
63 struct datalink_proto *if_dlink;
Al Viro4833ed02006-11-03 00:27:06 -080064 __be16 if_dlink_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 /* socket support */
67 unsigned short if_sknum;
68 struct hlist_head if_sklist;
69 spinlock_t if_sklist_lock;
70
71 /* administrative overhead */
72 int if_ipx_offset;
73 unsigned char if_internal;
74 unsigned char if_primary;
75
76 struct list_head node; /* node in ipx_interfaces list */
77};
78
79struct ipx_route {
Al Viro4833ed02006-11-03 00:27:06 -080080 __be32 ir_net;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 struct ipx_interface *ir_intrfc;
82 unsigned char ir_routed;
83 unsigned char ir_router_node[IPX_NODE_LEN];
84 struct list_head node; /* node in ipx_routes list */
Reshetova, Elena16f73c92017-07-04 15:53:10 +030085 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088struct ipx_cb {
89 u8 ipx_tctrl;
Al Viro4833ed02006-11-03 00:27:06 -080090 __be32 ipx_dest_net;
91 __be32 ipx_source_net;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 struct {
Al Viro4833ed02006-11-03 00:27:06 -080093 __be32 netnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 int index;
95 } last_hop;
96};
97
98#include <net/sock.h>
99
100struct ipx_sock {
101 /* struct sock has to be the first member of ipx_sock */
102 struct sock sk;
103 struct ipx_address dest_addr;
104 struct ipx_interface *intrfc;
Al Viro4833ed02006-11-03 00:27:06 -0800105 __be16 port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#ifdef CONFIG_IPX_INTERN
107 unsigned char node[IPX_NODE_LEN];
108#endif
109 unsigned short type;
110 /*
111 * To handle special ncp connection-handling sockets for mars_nwe,
112 * the connection number must be stored in the socket.
113 */
114 unsigned short ipx_ncp_conn;
115};
116
117static inline struct ipx_sock *ipx_sk(struct sock *sk)
118{
119 return (struct ipx_sock *)sk;
120}
121
122#define IPX_SKB_CB(__skb) ((struct ipx_cb *)&((__skb)->cb[0]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124#define IPX_MIN_EPHEMERAL_SOCKET 0x4000
125#define IPX_MAX_EPHEMERAL_SOCKET 0x7fff
126
127extern struct list_head ipx_routes;
128extern rwlock_t ipx_routes_lock;
129
130extern struct list_head ipx_interfaces;
Joe Perches9d036262013-09-21 10:22:43 -0700131struct ipx_interface *ipx_interfaces_head(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132extern spinlock_t ipx_interfaces_lock;
133
134extern struct ipx_interface *ipx_primary_net;
135
Joe Perches9d036262013-09-21 10:22:43 -0700136int ipx_proc_init(void);
137void ipx_proc_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Joe Perches9d036262013-09-21 10:22:43 -0700139const char *ipx_frame_name(__be16);
140const char *ipx_device_name(struct ipx_interface *intrfc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142static __inline__ void ipxitf_hold(struct ipx_interface *intrfc)
143{
Reshetova, Elenad25189c2017-07-04 15:53:09 +0300144 refcount_inc(&intrfc->refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Joe Perches9d036262013-09-21 10:22:43 -0700147void ipxitf_down(struct ipx_interface *intrfc);
Rashika Kheria493cc5e2014-02-09 22:24:33 +0530148struct ipx_interface *ipxitf_find_using_net(__be32 net);
149int ipxitf_send(struct ipx_interface *intrfc, struct sk_buff *skb, char *node);
150__be16 ipx_cksum(struct ipxhdr *packet, int length);
Rashika Kheria578efbc2014-02-09 22:26:32 +0530151int ipxrtr_add_route(__be32 network, struct ipx_interface *intrfc,
152 unsigned char *node);
153void ipxrtr_del_routes(struct ipx_interface *intrfc);
154int ipxrtr_route_packet(struct sock *sk, struct sockaddr_ipx *usipx,
Al Viroe1693712014-04-06 21:28:01 -0400155 struct msghdr *msg, size_t len, int noblock);
Rashika Kheria578efbc2014-02-09 22:26:32 +0530156int ipxrtr_route_skb(struct sk_buff *skb);
157struct ipx_route *ipxrtr_lookup(__be32 net);
158int ipxrtr_ioctl(unsigned int cmd, void __user *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160static __inline__ void ipxitf_put(struct ipx_interface *intrfc)
161{
Reshetova, Elenad25189c2017-07-04 15:53:09 +0300162 if (refcount_dec_and_test(&intrfc->refcnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 ipxitf_down(intrfc);
164}
165
166static __inline__ void ipxrtr_hold(struct ipx_route *rt)
167{
Reshetova, Elena16f73c92017-07-04 15:53:10 +0300168 refcount_inc(&rt->refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
171static __inline__ void ipxrtr_put(struct ipx_route *rt)
172{
Reshetova, Elena16f73c92017-07-04 15:53:10 +0300173 if (refcount_dec_and_test(&rt->refcnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 kfree(rt);
175}
176#endif /* _NET_INET_IPX_H_ */