dn_dev.h 5.4 KB

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