net.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * LiMon Monitor (LiMon) - Network.
  3. *
  4. * Copyright 1994 - 2000 Neil Russell.
  5. * (See License)
  6. *
  7. *
  8. * History
  9. * 9/16/00 bor adapted to TQM823L/STK8xxL board, RARP/TFTP boot added
  10. */
  11. #ifndef __NET_H__
  12. #define __NET_H__
  13. #if defined(CONFIG_8xx)
  14. #include <commproc.h>
  15. #endif /* CONFIG_8xx */
  16. #include <asm/cache.h>
  17. #include <asm/byteorder.h> /* for nton* / ntoh* stuff */
  18. /*
  19. * The number of receive packet buffers, and the required packet buffer
  20. * alignment in memory.
  21. *
  22. */
  23. #ifdef CONFIG_SYS_RX_ETH_BUFFER
  24. # define PKTBUFSRX CONFIG_SYS_RX_ETH_BUFFER
  25. #else
  26. # define PKTBUFSRX 4
  27. #endif
  28. #define PKTALIGN ARCH_DMA_MINALIGN
  29. /* IPv4 addresses are always 32 bits in size */
  30. typedef u32 IPaddr_t;
  31. /**
  32. * An incoming packet handler.
  33. * @param pkt pointer to the application packet
  34. * @param dport destination UDP port
  35. * @param sip source IP address
  36. * @param sport source UDP port
  37. * @param len packet length
  38. */
  39. typedef void rxhand_f(uchar *pkt, unsigned dport,
  40. IPaddr_t sip, unsigned sport,
  41. unsigned len);
  42. /**
  43. * An incoming ICMP packet handler.
  44. * @param type ICMP type
  45. * @param code ICMP code
  46. * @param dport destination UDP port
  47. * @param sip source IP address
  48. * @param sport source UDP port
  49. * @param pkt pointer to the ICMP packet data
  50. * @param len packet length
  51. */
  52. typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport,
  53. IPaddr_t sip, unsigned sport, uchar *pkt, unsigned len);
  54. /*
  55. * A timeout handler. Called after time interval has expired.
  56. */
  57. typedef void thand_f(void);
  58. enum eth_state_t {
  59. ETH_STATE_INIT,
  60. ETH_STATE_PASSIVE,
  61. ETH_STATE_ACTIVE
  62. };
  63. struct eth_device {
  64. char name[16];
  65. unsigned char enetaddr[6];
  66. int iobase;
  67. int state;
  68. int (*init) (struct eth_device *, bd_t *);
  69. int (*send) (struct eth_device *, void *packet, int length);
  70. int (*recv) (struct eth_device *);
  71. void (*halt) (struct eth_device *);
  72. #ifdef CONFIG_MCAST_TFTP
  73. int (*mcast) (struct eth_device *, u32 ip, u8 set);
  74. #endif
  75. int (*write_hwaddr) (struct eth_device *);
  76. struct eth_device *next;
  77. int index;
  78. void *priv;
  79. };
  80. extern int eth_initialize(bd_t *bis); /* Initialize network subsystem */
  81. extern int eth_register(struct eth_device* dev);/* Register network device */
  82. extern int eth_unregister(struct eth_device *dev);/* Remove network device */
  83. extern void eth_try_another(int first_restart); /* Change the device */
  84. extern void eth_set_current(void); /* set nterface to ethcur var */
  85. extern struct eth_device *eth_get_dev(void); /* get the current device MAC */
  86. extern struct eth_device *eth_get_dev_by_name(const char *devname);
  87. extern struct eth_device *eth_get_dev_by_index(int index); /* get dev @ index */
  88. extern int eth_get_dev_index(void); /* get the device index */
  89. extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
  90. extern int eth_getenv_enetaddr(char *name, uchar *enetaddr);
  91. extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
  92. /*
  93. * Get the hardware address for an ethernet interface .
  94. * Args:
  95. * base_name - base name for device (normally "eth")
  96. * index - device index number (0 for first)
  97. * enetaddr - returns 6 byte hardware address
  98. * Returns:
  99. * Return true if the address is valid.
  100. */
  101. extern int eth_getenv_enetaddr_by_index(const char *base_name, int index,
  102. uchar *enetaddr);
  103. extern int usb_eth_initialize(bd_t *bi);
  104. extern int eth_init(bd_t *bis); /* Initialize the device */
  105. extern int eth_send(void *packet, int length); /* Send a packet */
  106. #ifdef CONFIG_API
  107. extern int eth_receive(void *packet, int length); /* Receive a packet*/
  108. extern void (*push_packet)(void *packet, int length);
  109. #endif
  110. extern int eth_rx(void); /* Check for received packets */
  111. extern void eth_halt(void); /* stop SCC */
  112. extern char *eth_get_name(void); /* get name of current device */
  113. /*
  114. * Set the hardware address for an ethernet interface based on 'eth%daddr'
  115. * environment variable (or just 'ethaddr' if eth_number is 0).
  116. * Args:
  117. * base_name - base name for device (normally "eth")
  118. * eth_number - value of %d (0 for first device of this type)
  119. * Returns:
  120. * 0 is success, non-zero is error status from driver.
  121. */
  122. int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
  123. int eth_number);
  124. #ifdef CONFIG_MCAST_TFTP
  125. int eth_mcast_join(IPaddr_t mcast_addr, u8 join);
  126. u32 ether_crc(size_t len, unsigned char const *p);
  127. #endif
  128. /**********************************************************************/
  129. /*
  130. * Protocol headers.
  131. */
  132. /*
  133. * Ethernet header
  134. */
  135. struct ethernet_hdr {
  136. uchar et_dest[6]; /* Destination node */
  137. uchar et_src[6]; /* Source node */
  138. ushort et_protlen; /* Protocol or length */
  139. };
  140. /* Ethernet header size */
  141. #define ETHER_HDR_SIZE (sizeof(struct ethernet_hdr))
  142. struct e802_hdr {
  143. uchar et_dest[6]; /* Destination node */
  144. uchar et_src[6]; /* Source node */
  145. ushort et_protlen; /* Protocol or length */
  146. uchar et_dsap; /* 802 DSAP */
  147. uchar et_ssap; /* 802 SSAP */
  148. uchar et_ctl; /* 802 control */
  149. uchar et_snap1; /* SNAP */
  150. uchar et_snap2;
  151. uchar et_snap3;
  152. ushort et_prot; /* 802 protocol */
  153. };
  154. /* 802 + SNAP + ethernet header size */
  155. #define E802_HDR_SIZE (sizeof(struct e802_hdr))
  156. /*
  157. * Virtual LAN Ethernet header
  158. */
  159. struct vlan_ethernet_hdr {
  160. uchar vet_dest[6]; /* Destination node */
  161. uchar vet_src[6]; /* Source node */
  162. ushort vet_vlan_type; /* PROT_VLAN */
  163. ushort vet_tag; /* TAG of VLAN */
  164. ushort vet_type; /* protocol type */
  165. };
  166. /* VLAN Ethernet header size */
  167. #define VLAN_ETHER_HDR_SIZE (sizeof(struct vlan_ethernet_hdr))
  168. #define PROT_IP 0x0800 /* IP protocol */
  169. #define PROT_ARP 0x0806 /* IP ARP protocol */
  170. #define PROT_RARP 0x8035 /* IP ARP protocol */
  171. #define PROT_VLAN 0x8100 /* IEEE 802.1q protocol */
  172. #define IPPROTO_ICMP 1 /* Internet Control Message Protocol */
  173. #define IPPROTO_UDP 17 /* User Datagram Protocol */
  174. /*
  175. * Internet Protocol (IP) header.
  176. */
  177. struct ip_hdr {
  178. uchar ip_hl_v; /* header length and version */
  179. uchar ip_tos; /* type of service */
  180. ushort ip_len; /* total length */
  181. ushort ip_id; /* identification */
  182. ushort ip_off; /* fragment offset field */
  183. uchar ip_ttl; /* time to live */
  184. uchar ip_p; /* protocol */
  185. ushort ip_sum; /* checksum */
  186. IPaddr_t ip_src; /* Source IP address */
  187. IPaddr_t ip_dst; /* Destination IP address */
  188. };
  189. #define IP_OFFS 0x1fff /* ip offset *= 8 */
  190. #define IP_FLAGS 0xe000 /* first 3 bits */
  191. #define IP_FLAGS_RES 0x8000 /* reserved */
  192. #define IP_FLAGS_DFRAG 0x4000 /* don't fragments */
  193. #define IP_FLAGS_MFRAG 0x2000 /* more fragments */
  194. #define IP_HDR_SIZE (sizeof(struct ip_hdr))
  195. /*
  196. * Internet Protocol (IP) + UDP header.
  197. */
  198. struct ip_udp_hdr {
  199. uchar ip_hl_v; /* header length and version */
  200. uchar ip_tos; /* type of service */
  201. ushort ip_len; /* total length */
  202. ushort ip_id; /* identification */
  203. ushort ip_off; /* fragment offset field */
  204. uchar ip_ttl; /* time to live */
  205. uchar ip_p; /* protocol */
  206. ushort ip_sum; /* checksum */
  207. IPaddr_t ip_src; /* Source IP address */
  208. IPaddr_t ip_dst; /* Destination IP address */
  209. ushort udp_src; /* UDP source port */
  210. ushort udp_dst; /* UDP destination port */
  211. ushort udp_len; /* Length of UDP packet */
  212. ushort udp_xsum; /* Checksum */
  213. };
  214. #define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr))
  215. #define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE)
  216. /*
  217. * Address Resolution Protocol (ARP) header.
  218. */
  219. struct arp_hdr {
  220. ushort ar_hrd; /* Format of hardware address */
  221. # define ARP_ETHER 1 /* Ethernet hardware address */
  222. ushort ar_pro; /* Format of protocol address */
  223. uchar ar_hln; /* Length of hardware address */
  224. # define ARP_HLEN 6
  225. uchar ar_pln; /* Length of protocol address */
  226. # define ARP_PLEN 4
  227. ushort ar_op; /* Operation */
  228. # define ARPOP_REQUEST 1 /* Request to resolve address */
  229. # define ARPOP_REPLY 2 /* Response to previous request */
  230. # define RARPOP_REQUEST 3 /* Request to resolve address */
  231. # define RARPOP_REPLY 4 /* Response to previous request */
  232. /*
  233. * The remaining fields are variable in size, according to
  234. * the sizes above, and are defined as appropriate for
  235. * specific hardware/protocol combinations.
  236. */
  237. uchar ar_data[0];
  238. #define ar_sha ar_data[0]
  239. #define ar_spa ar_data[ARP_HLEN]
  240. #define ar_tha ar_data[ARP_HLEN + ARP_PLEN]
  241. #define ar_tpa ar_data[ARP_HLEN + ARP_PLEN + ARP_HLEN]
  242. #if 0
  243. uchar ar_sha[]; /* Sender hardware address */
  244. uchar ar_spa[]; /* Sender protocol address */
  245. uchar ar_tha[]; /* Target hardware address */
  246. uchar ar_tpa[]; /* Target protocol address */
  247. #endif /* 0 */
  248. };
  249. #define ARP_HDR_SIZE (8+20) /* Size assuming ethernet */
  250. /*
  251. * ICMP stuff (just enough to handle (host) redirect messages)
  252. */
  253. #define ICMP_ECHO_REPLY 0 /* Echo reply */
  254. #define ICMP_NOT_REACH 3 /* Detination unreachable */
  255. #define ICMP_REDIRECT 5 /* Redirect (change route) */
  256. #define ICMP_ECHO_REQUEST 8 /* Echo request */
  257. /* Codes for REDIRECT. */
  258. #define ICMP_REDIR_NET 0 /* Redirect Net */
  259. #define ICMP_REDIR_HOST 1 /* Redirect Host */
  260. /* Codes for NOT_REACH */
  261. #define ICMP_NOT_REACH_PORT 3 /* Port unreachable */
  262. struct icmp_hdr {
  263. uchar type;
  264. uchar code;
  265. ushort checksum;
  266. union {
  267. struct {
  268. ushort id;
  269. ushort sequence;
  270. } echo;
  271. ulong gateway;
  272. struct {
  273. ushort __unused;
  274. ushort mtu;
  275. } frag;
  276. uchar data[0];
  277. } un;
  278. };
  279. #define ICMP_HDR_SIZE (sizeof(struct icmp_hdr))
  280. #define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE)
  281. /*
  282. * Maximum packet size; used to allocate packet storage.
  283. * TFTP packets can be 524 bytes + IP header + ethernet header.
  284. * Lets be conservative, and go for 38 * 16. (Must also be
  285. * a multiple of 32 bytes).
  286. */
  287. /*
  288. * AS.HARNOIS : Better to set PKTSIZE to maximum size because
  289. * traffic type is not always controlled
  290. * maximum packet size = 1518
  291. * maximum packet size and multiple of 32 bytes = 1536
  292. */
  293. #define PKTSIZE 1518
  294. #define PKTSIZE_ALIGN 1536
  295. /*#define PKTSIZE 608*/
  296. /*
  297. * Maximum receive ring size; that is, the number of packets
  298. * we can buffer before overflow happens. Basically, this just
  299. * needs to be enough to prevent a packet being discarded while
  300. * we are processing the previous one.
  301. */
  302. #define RINGSZ 4
  303. #define RINGSZ_LOG2 2
  304. /**********************************************************************/
  305. /*
  306. * Globals.
  307. *
  308. * Note:
  309. *
  310. * All variables of type IPaddr_t are stored in NETWORK byte order
  311. * (big endian).
  312. */
  313. /* net.c */
  314. /** BOOTP EXTENTIONS **/
  315. extern IPaddr_t NetOurGatewayIP; /* Our gateway IP address */
  316. extern IPaddr_t NetOurSubnetMask; /* Our subnet mask (0 = unknown) */
  317. extern IPaddr_t NetOurDNSIP; /* Our Domain Name Server (0 = unknown) */
  318. #if defined(CONFIG_BOOTP_DNS2)
  319. extern IPaddr_t NetOurDNS2IP; /* Our 2nd Domain Name Server (0 = unknown) */
  320. #endif
  321. extern char NetOurNISDomain[32]; /* Our NIS domain */
  322. extern char NetOurHostName[32]; /* Our hostname */
  323. extern char NetOurRootPath[64]; /* Our root path */
  324. extern ushort NetBootFileSize; /* Our boot file size in blocks */
  325. /** END OF BOOTP EXTENTIONS **/
  326. extern ulong NetBootFileXferSize; /* size of bootfile in bytes */
  327. extern uchar NetOurEther[6]; /* Our ethernet address */
  328. extern uchar NetServerEther[6]; /* Boot server enet address */
  329. extern IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */
  330. extern IPaddr_t NetServerIP; /* Server IP addr (0 = unknown) */
  331. extern uchar *NetTxPacket; /* THE transmit packet */
  332. extern uchar *NetRxPackets[PKTBUFSRX]; /* Receive packets */
  333. extern uchar *NetRxPacket; /* Current receive packet */
  334. extern int NetRxPacketLen; /* Current rx packet length */
  335. extern unsigned NetIPID; /* IP ID (counting) */
  336. extern uchar NetBcastAddr[6]; /* Ethernet boardcast address */
  337. extern uchar NetEtherNullAddr[6];
  338. #define VLAN_NONE 4095 /* untagged */
  339. #define VLAN_IDMASK 0x0fff /* mask of valid vlan id */
  340. extern ushort NetOurVLAN; /* Our VLAN */
  341. extern ushort NetOurNativeVLAN; /* Our Native VLAN */
  342. extern int NetRestartWrap; /* Tried all network devices */
  343. enum proto_t {
  344. BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
  345. TFTPSRV, TFTPPUT, LINKLOCAL
  346. };
  347. /* from net/net.c */
  348. extern char BootFile[128]; /* Boot File name */
  349. #if defined(CONFIG_CMD_DNS)
  350. extern char *NetDNSResolve; /* The host to resolve */
  351. extern char *NetDNSenvvar; /* the env var to put the ip into */
  352. #endif
  353. #if defined(CONFIG_CMD_PING)
  354. extern IPaddr_t NetPingIP; /* the ip address to ping */
  355. #endif
  356. #if defined(CONFIG_CMD_CDP)
  357. /* when CDP completes these hold the return values */
  358. extern ushort CDPNativeVLAN; /* CDP returned native VLAN */
  359. extern ushort CDPApplianceVLAN; /* CDP returned appliance VLAN */
  360. /*
  361. * Check for a CDP packet by examining the received MAC address field
  362. */
  363. static inline int is_cdp_packet(const uchar *et_addr)
  364. {
  365. extern const uchar NetCDPAddr[6];
  366. return memcmp(et_addr, NetCDPAddr, 6) == 0;
  367. }
  368. #endif
  369. #if defined(CONFIG_CMD_SNTP)
  370. extern IPaddr_t NetNtpServerIP; /* the ip address to NTP */
  371. extern int NetTimeOffset; /* offset time from UTC */
  372. #endif
  373. #if defined(CONFIG_MCAST_TFTP)
  374. extern IPaddr_t Mcast_addr;
  375. #endif
  376. /* Initialize the network adapter */
  377. extern void net_init(void);
  378. extern int NetLoop(enum proto_t);
  379. /* Shutdown adapters and cleanup */
  380. extern void NetStop(void);
  381. /* Load failed. Start again. */
  382. extern void NetStartAgain(void);
  383. /* Get size of the ethernet header when we send */
  384. extern int NetEthHdrSize(void);
  385. /* Set ethernet header; returns the size of the header */
  386. extern int NetSetEther(uchar *, uchar *, uint);
  387. extern int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot);
  388. /* Set IP header */
  389. extern void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source);
  390. extern void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport,
  391. int sport, int len);
  392. /* Checksum */
  393. extern int NetCksumOk(uchar *, int); /* Return true if cksum OK */
  394. extern uint NetCksum(uchar *, int); /* Calculate the checksum */
  395. /* Callbacks */
  396. extern rxhand_f *net_get_udp_handler(void); /* Get UDP RX packet handler */
  397. extern void net_set_udp_handler(rxhand_f *); /* Set UDP RX packet handler */
  398. extern rxhand_f *net_get_arp_handler(void); /* Get ARP RX packet handler */
  399. extern void net_set_arp_handler(rxhand_f *); /* Set ARP RX packet handler */
  400. extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
  401. extern void NetSetTimeout(ulong, thand_f *);/* Set timeout handler */
  402. /* Network loop state */
  403. enum net_loop_state {
  404. NETLOOP_CONTINUE,
  405. NETLOOP_RESTART,
  406. NETLOOP_SUCCESS,
  407. NETLOOP_FAIL
  408. };
  409. static inline void net_set_state(enum net_loop_state state)
  410. {
  411. extern enum net_loop_state net_state;
  412. net_state = state;
  413. }
  414. /* Transmit a packet */
  415. static inline void NetSendPacket(uchar *pkt, int len)
  416. {
  417. (void) eth_send(pkt, len);
  418. }
  419. /*
  420. * Transmit "NetTxPacket" as UDP packet, performing ARP request if needed
  421. * (ether will be populated)
  422. *
  423. * @param ether Raw packet buffer
  424. * @param dest IP address to send the datagram to
  425. * @param dport Destination UDP port
  426. * @param sport Source UDP port
  427. * @param payload_len Length of data after the UDP header
  428. */
  429. extern int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
  430. int sport, int payload_len);
  431. /* Processes a received packet */
  432. extern void NetReceive(uchar *, int);
  433. #ifdef CONFIG_NETCONSOLE
  434. void NcStart(void);
  435. int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
  436. #endif
  437. /*
  438. * Check if autoload is enabled. If so, use either NFS or TFTP to download
  439. * the boot file.
  440. */
  441. void net_auto_load(void);
  442. /*
  443. * The following functions are a bit ugly, but necessary to deal with
  444. * alignment restrictions on ARM.
  445. *
  446. * We're using inline functions, which had the smallest memory
  447. * footprint in our tests.
  448. */
  449. /* return IP *in network byteorder* */
  450. static inline IPaddr_t NetReadIP(void *from)
  451. {
  452. IPaddr_t ip;
  453. memcpy((void *)&ip, (void *)from, sizeof(ip));
  454. return ip;
  455. }
  456. /* return ulong *in network byteorder* */
  457. static inline ulong NetReadLong(ulong *from)
  458. {
  459. ulong l;
  460. memcpy((void *)&l, (void *)from, sizeof(l));
  461. return l;
  462. }
  463. /* write IP *in network byteorder* */
  464. static inline void NetWriteIP(void *to, IPaddr_t ip)
  465. {
  466. memcpy(to, (void *)&ip, sizeof(ip));
  467. }
  468. /* copy IP */
  469. static inline void NetCopyIP(void *to, void *from)
  470. {
  471. memcpy((void *)to, from, sizeof(IPaddr_t));
  472. }
  473. /* copy ulong */
  474. static inline void NetCopyLong(ulong *to, ulong *from)
  475. {
  476. memcpy((void *)to, (void *)from, sizeof(ulong));
  477. }
  478. /**
  479. * is_zero_ether_addr - Determine if give Ethernet address is all zeros.
  480. * @addr: Pointer to a six-byte array containing the Ethernet address
  481. *
  482. * Return true if the address is all zeroes.
  483. */
  484. static inline int is_zero_ether_addr(const u8 *addr)
  485. {
  486. return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
  487. }
  488. /**
  489. * is_multicast_ether_addr - Determine if the Ethernet address is a multicast.
  490. * @addr: Pointer to a six-byte array containing the Ethernet address
  491. *
  492. * Return true if the address is a multicast address.
  493. * By definition the broadcast address is also a multicast address.
  494. */
  495. static inline int is_multicast_ether_addr(const u8 *addr)
  496. {
  497. return 0x01 & addr[0];
  498. }
  499. /*
  500. * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast
  501. * @addr: Pointer to a six-byte array containing the Ethernet address
  502. *
  503. * Return true if the address is the broadcast address.
  504. */
  505. static inline int is_broadcast_ether_addr(const u8 *addr)
  506. {
  507. return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) ==
  508. 0xff;
  509. }
  510. /*
  511. * is_valid_ether_addr - Determine if the given Ethernet address is valid
  512. * @addr: Pointer to a six-byte array containing the Ethernet address
  513. *
  514. * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not
  515. * a multicast address, and is not FF:FF:FF:FF:FF:FF.
  516. *
  517. * Return true if the address is valid.
  518. */
  519. static inline int is_valid_ether_addr(const u8 *addr)
  520. {
  521. /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to
  522. * explicitly check for it here. */
  523. return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
  524. }
  525. /* Convert an IP address to a string */
  526. extern void ip_to_string(IPaddr_t x, char *s);
  527. /* Convert a string to ip address */
  528. extern IPaddr_t string_to_ip(const char *s);
  529. /* Convert a VLAN id to a string */
  530. extern void VLAN_to_string(ushort x, char *s);
  531. /* Convert a string to a vlan id */
  532. extern ushort string_to_VLAN(const char *s);
  533. /* read a VLAN id from an environment variable */
  534. extern ushort getenv_VLAN(char *);
  535. /* copy a filename (allow for "..." notation, limit length) */
  536. extern void copy_filename(char *dst, const char *src, int size);
  537. /* get a random source port */
  538. extern unsigned int random_port(void);
  539. /**********************************************************************/
  540. #endif /* __NET_H__ */