net: add missing includes and forward declarations under net/
[linux-2.6-microblaze.git] / include / net / dn_dev.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_DN_DEV_H
3 #define _NET_DN_DEV_H
4
5 #include <linux/netdevice.h>
6
7 struct dn_dev;
8
9 struct dn_ifaddr {
10         struct dn_ifaddr __rcu *ifa_next;
11         struct dn_dev    *ifa_dev;
12         __le16            ifa_local;
13         __le16            ifa_address;
14         __u32             ifa_flags;
15         __u8              ifa_scope;
16         char              ifa_label[IFNAMSIZ];
17         struct rcu_head   rcu;
18 };
19
20 #define DN_DEV_S_RU  0 /* Run - working normally   */
21 #define DN_DEV_S_CR  1 /* Circuit Rejected         */
22 #define DN_DEV_S_DS  2 /* Data Link Start          */
23 #define DN_DEV_S_RI  3 /* Routing Layer Initialize */
24 #define DN_DEV_S_RV  4 /* Routing Layer Verify     */
25 #define DN_DEV_S_RC  5 /* Routing Layer Complete   */
26 #define DN_DEV_S_OF  6 /* Off                      */
27 #define DN_DEV_S_HA  7 /* Halt                     */
28
29
30 /*
31  * The dn_dev_parms structure contains the set of parameters
32  * for each device (hence inclusion in the dn_dev structure)
33  * and an array is used to store the default types of supported
34  * device (in dn_dev.c).
35  *
36  * The type field matches the ARPHRD_ constants and is used in
37  * searching the list for supported devices when new devices
38  * come up.
39  *
40  * The mode field is used to find out if a device is broadcast,
41  * multipoint, or pointopoint. Please note that DECnet thinks
42  * different ways about devices to the rest of the kernel
43  * so the normal IFF_xxx flags are invalid here. For devices
44  * which can be any combination of the previously mentioned
45  * attributes, you can set this on a per device basis by
46  * installing an up() routine.
47  *
48  * The device state field, defines the initial state in which the
49  * device will come up. In the dn_dev structure, it is the actual
50  * state.
51  *
52  * Things have changed here. I've killed timer1 since it's a user space
53  * issue for a user space routing deamon to sort out. The kernel does
54  * not need to be bothered with it.
55  *
56  * Timers:
57  * t2 - Rate limit timer, min time between routing and hello messages
58  * t3 - Hello timer, send hello messages when it expires
59  *
60  * Callbacks:
61  * up() - Called to initialize device, return value can veto use of
62  *        device with DECnet.
63  * down() - Called to turn device off when it goes down
64  * timer3() - Called once for each ifaddr when timer 3 goes off
65  * 
66  * sysctl - Hook for sysctl things
67  *
68  */
69 struct dn_dev_parms {
70         int type;                 /* ARPHRD_xxx                         */
71         int mode;                 /* Broadcast, Unicast, Mulitpoint     */
72 #define DN_DEV_BCAST  1
73 #define DN_DEV_UCAST  2
74 #define DN_DEV_MPOINT 4
75         int state;                /* Initial state                      */
76         int forwarding;           /* 0=EndNode, 1=L1Router, 2=L2Router  */
77         unsigned long t2;         /* Default value of t2                */
78         unsigned long t3;         /* Default value of t3                */
79         int priority;             /* Priority to be a router            */
80         char *name;               /* Name for sysctl                    */
81         int  (*up)(struct net_device *);
82         void (*down)(struct net_device *);
83         void (*timer3)(struct net_device *, struct dn_ifaddr *ifa);
84         void *sysctl;
85 };
86
87
88 struct dn_dev {
89         struct dn_ifaddr __rcu *ifa_list;
90         struct net_device *dev;
91         struct dn_dev_parms parms;
92         char use_long;
93         struct timer_list timer;
94         unsigned long t3;
95         struct neigh_parms *neigh_parms;
96         __u8 addr[ETH_ALEN];
97         struct neighbour *router; /* Default router on circuit */
98         struct neighbour *peer;   /* Peer on pointopoint links */
99         unsigned long uptime;     /* Time device went up in jiffies */
100 };
101
102 struct dn_short_packet {
103         __u8    msgflg;
104         __le16 dstnode;
105         __le16 srcnode;
106         __u8   forward;
107 } __packed;
108
109 struct dn_long_packet {
110         __u8   msgflg;
111         __u8   d_area;
112         __u8   d_subarea;
113         __u8   d_id[6];
114         __u8   s_area;
115         __u8   s_subarea;
116         __u8   s_id[6];
117         __u8   nl2;
118         __u8   visit_ct;
119         __u8   s_class;
120         __u8   pt;
121 } __packed;
122
123 /*------------------------- DRP - Routing messages ---------------------*/
124
125 struct endnode_hello_message {
126         __u8   msgflg;
127         __u8   tiver[3];
128         __u8   id[6];
129         __u8   iinfo;
130         __le16 blksize;
131         __u8   area;
132         __u8   seed[8];
133         __u8   neighbor[6];
134         __le16 timer;
135         __u8   mpd;
136         __u8   datalen;
137         __u8   data[2];
138 } __packed;
139
140 struct rtnode_hello_message {
141         __u8   msgflg;
142         __u8   tiver[3];
143         __u8   id[6];
144         __u8   iinfo;
145         __le16  blksize;
146         __u8   priority;
147         __u8   area;
148         __le16  timer;
149         __u8   mpd;
150 } __packed;
151
152
153 void dn_dev_init(void);
154 void dn_dev_cleanup(void);
155
156 int dn_dev_ioctl(unsigned int cmd, void __user *arg);
157
158 void dn_dev_devices_off(void);
159 void dn_dev_devices_on(void);
160
161 void dn_dev_init_pkt(struct sk_buff *skb);
162 void dn_dev_veri_pkt(struct sk_buff *skb);
163 void dn_dev_hello(struct sk_buff *skb);
164
165 void dn_dev_up(struct net_device *);
166 void dn_dev_down(struct net_device *);
167
168 int dn_dev_set_default(struct net_device *dev, int force);
169 struct net_device *dn_dev_get_default(void);
170 int dn_dev_bind_default(__le16 *addr);
171
172 int register_dnaddr_notifier(struct notifier_block *nb);
173 int unregister_dnaddr_notifier(struct notifier_block *nb);
174
175 static inline int dn_dev_islocal(struct net_device *dev, __le16 addr)
176 {
177         struct dn_dev *dn_db;
178         struct dn_ifaddr *ifa;
179         int res = 0;
180
181         rcu_read_lock();
182         dn_db = rcu_dereference(dev->dn_ptr);
183         if (dn_db == NULL) {
184                 printk(KERN_DEBUG "dn_dev_islocal: Called for non DECnet device\n");
185                 goto out;
186         }
187
188         for (ifa = rcu_dereference(dn_db->ifa_list);
189              ifa != NULL;
190              ifa = rcu_dereference(ifa->ifa_next))
191                 if ((addr ^ ifa->ifa_local) == 0) {
192                         res = 1;
193                         break;
194                 }
195 out:
196         rcu_read_unlock();
197         return res;
198 }
199
200 #endif /* _NET_DN_DEV_H */