Browse Source

Moved if_ether.h and if_arp.h to include/gpxe, for consistency with Linux

kernel.

Removed obsolete struct arprequest from if_arp.h and put it in nic.c so
that nic.c will still compile.  ARP will very shortly be handled by
net/arp.c instead.
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
49f933fbc3
5 changed files with 130 additions and 37 deletions
  1. 17
    5
      src/core/nic.c
  2. 2
    2
      src/include/etherboot.h
  3. 100
    0
      src/include/gpxe/if_arp.h
  4. 11
    7
      src/include/gpxe/if_ether.h
  5. 0
    23
      src/include/if_arp.h

+ 17
- 5
src/core/nic.c View File

@@ -24,6 +24,18 @@ Literature dealing with the network protocols:
24 24
 #include "background.h"
25 25
 #include "elf.h" /* FOR EM_CURRENT */
26 26
 
27
+struct arprequest {
28
+        uint16_t hwtype;
29
+        uint16_t protocol;
30
+        uint8_t  hwlen;
31
+        uint8_t  protolen;
32
+        uint16_t opcode;
33
+        uint8_t  shwaddr[6];
34
+        uint8_t  sipaddr[4];
35
+        uint8_t  thwaddr[6];
36
+        uint8_t  tipaddr[4];
37
+} PACKED;
38
+
27 39
 struct arptable_t	arptable[MAX_ARP];
28 40
 /* Put rom_info in .nocompress section so romprefix.S can write to it */
29 41
 struct rom_info	rom __attribute__ ((section (".text16.nocompress"))) = {0,0};
@@ -427,7 +439,7 @@ static int await_arp(int ival, void *ptr,
427 439
 		return 0;
428 440
 	arpreply = (struct arprequest *)&nic.packet[ETH_HLEN];
429 441
 
430
-	if (arpreply->opcode != htons(ARP_REPLY)) 
442
+	if (arpreply->opcode != htons(ARPOP_REPLY)) 
431 443
 		return 0;
432 444
 	if (memcmp(arpreply->sipaddr, ptr, sizeof(in_addr)) != 0)
433 445
 		return 0;
@@ -474,10 +486,10 @@ int ip_transmit(int len, const void *buf)
474 486
 				break;
475 487
 		if (i == ETH_ALEN) {	/* Need to do arp request */
476 488
 			arpreq.hwtype = htons(1);
477
-			arpreq.protocol = htons(IP);
489
+			arpreq.protocol = htons(ETH_P_IP);
478 490
 			arpreq.hwlen = ETH_ALEN;
479 491
 			arpreq.protolen = 4;
480
-			arpreq.opcode = htons(ARP_REQUEST);
492
+			arpreq.opcode = htons(ARPOP_REQUEST);
481 493
 			memcpy(arpreq.shwaddr, arptable[ARP_CLIENT].node, ETH_ALEN);
482 494
 			memcpy(arpreq.sipaddr, &arptable[ARP_CLIENT].ipaddr, sizeof(in_addr));
483 495
 			memset(arpreq.thwaddr, 0, ETH_ALEN);
@@ -974,9 +986,9 @@ int await_reply(reply_t reply, int ival, void *ptr, long timeout)
974 986
 		
975 987
 			arpreply = (struct arprequest *)&nic.packet[ETH_HLEN];
976 988
 			memcpy(&tmp, arpreply->tipaddr, sizeof(in_addr));
977
-			if ((arpreply->opcode == htons(ARP_REQUEST)) &&
989
+			if ((arpreply->opcode == htons(ARPOP_REQUEST)) &&
978 990
 				(tmp == arptable[ARP_CLIENT].ipaddr.s_addr)) {
979
-				arpreply->opcode = htons(ARP_REPLY);
991
+				arpreply->opcode = htons(ARPOP_REPLY);
980 992
 				memcpy(arpreply->tipaddr, arpreply->sipaddr, sizeof(in_addr));
981 993
 				memcpy(arpreply->thwaddr, arpreply->shwaddr, ETH_ALEN);
982 994
 				memcpy(arpreply->sipaddr, &arptable[ARP_CLIENT].ipaddr, sizeof(in_addr));

+ 2
- 2
src/include/etherboot.h View File

@@ -119,7 +119,7 @@
119 119
 #define NULL	((void *)0)
120 120
 #endif
121 121
 
122
-#include	"if_ether.h"
122
+#include	<gpxe/if_ether.h>
123 123
 
124 124
 enum {
125 125
 	ARP_CLIENT, ARP_SERVER, ARP_GATEWAY,
@@ -144,7 +144,7 @@ enum {
144 144
 #define ENCAP_OPT
145 145
 #endif
146 146
 
147
-#include	"if_arp.h"
147
+#include	<gpxe/if_arp.h>
148 148
 #include	"ip.h"
149 149
 #include	"udp.h"
150 150
 #include	"old_tcp.h"

+ 100
- 0
src/include/gpxe/if_arp.h View File

@@ -0,0 +1,100 @@
1
+#ifndef	_IF_ARP_H
2
+#define	_IF_ARP_H
3
+
4
+/** @file
5
+ *
6
+ * Address Resolution Protocol constants and types
7
+ *
8
+ */
9
+
10
+#include <stdint.h>
11
+
12
+/* ARP protocol HARDWARE identifiers. */
13
+#define ARPHRD_NETROM	0		/**< from KA9Q: NET/ROM pseudo	*/
14
+#define ARPHRD_ETHER 	1		/**< Ethernet 10Mbps		*/
15
+#define	ARPHRD_EETHER	2		/**< Experimental Ethernet	*/
16
+#define	ARPHRD_AX25	3		/**< AX.25 Level 2		*/
17
+#define	ARPHRD_PRONET	4		/**< PROnet token ring		*/
18
+#define	ARPHRD_CHAOS	5		/**< Chaosnet			*/
19
+#define	ARPHRD_IEEE802	6		/**< IEEE 802.2 Ethernet/TR/TB	*/
20
+#define	ARPHRD_ARCNET	7		/**< ARCnet			*/
21
+#define	ARPHRD_APPLETLK	8		/**< APPLEtalk			*/
22
+#define ARPHRD_DLCI	15		/**< Frame Relay DLCI		*/
23
+#define ARPHRD_ATM	19		/**< ATM 			*/
24
+#define ARPHRD_METRICOM	23		/**< Metricom STRIP (new IANA id) */
25
+#define	ARPHRD_IEEE1394	24		/**< IEEE 1394 IPv4 - RFC 2734	*/
26
+#define ARPHRD_EUI64	27		/**< EUI-64			*/
27
+#define ARPHRD_INFINIBAND 32		/**< InfiniBand			*/
28
+
29
+/* ARP protocol opcodes. */
30
+#define	ARPOP_REQUEST	1		/**< ARP request		*/
31
+#define	ARPOP_REPLY	2		/**< ARP reply			*/
32
+#define	ARPOP_RREQUEST	3		/**< RARP request		*/
33
+#define	ARPOP_RREPLY	4		/**< RARP reply			*/
34
+#define	ARPOP_InREQUEST	8		/**< InARP request		*/
35
+#define	ARPOP_InREPLY	9		/**< InARP reply		*/
36
+#define	ARPOP_NAK	10		/**< (ATM)ARP NAK		*/
37
+
38
+/**
39
+ * An ARP header
40
+ *
41
+ * This contains only the fixed-size portions of an ARP header; for
42
+ * other fields use the arp_{sender,target}_{ha,pa} family of
43
+ * functions.
44
+ */
45
+struct arphdr {
46
+	/** Link-layer protocol
47
+	 *
48
+	 * This is an ARPHRD_XXX constant
49
+	 */
50
+	uint16_t ar_hrd;
51
+	/** Network-layer protocol
52
+	 *
53
+	 * This is, for Ethernet, an ETH_P_XXX constant.
54
+	 */
55
+	uint16_t ar_pro;
56
+	/** Link-layer address length */
57
+	uint8_t ar_hln;
58
+	/** Network-layer address length */
59
+	uint8_t ar_pln;
60
+	/** ARP opcode */
61
+	uint16_t ar_op;
62
+} __attribute__ (( packed ));
63
+
64
+/** ARP packet sender hardware address
65
+ *
66
+ * @v arphdr	ARP header
67
+ * @ret ar_sha	Sender hardware address
68
+ */
69
+static inline void * arp_sender_ha ( struct arphdr *arphdr ) {
70
+	return ( ( ( void * ) arphdr ) + sizeof ( *arphdr ) );
71
+}
72
+
73
+/** ARP packet sender protocol address
74
+ *
75
+ * @v arphdr	ARP header
76
+ * @ret ar_spa	Sender protocol address
77
+ */
78
+static inline void * arp_sender_pa ( struct arphdr *arphdr ) {
79
+	return ( arp_sender_ha ( arphdr ) + arphdr->ar_hln );
80
+}
81
+
82
+/** ARP packet target hardware address
83
+ *
84
+ * @v arphdr	ARP header
85
+ * @ret ar_tha	Target hardware address
86
+ */
87
+static inline void * arp_target_ha ( struct arphdr *arphdr ) {
88
+	return ( arp_sender_pa ( arphdr ) + arphdr->ar_pln );
89
+}
90
+
91
+/** ARP packet target protocol address
92
+ *
93
+ * @v arphdr	ARP header
94
+ * @ret ar_tpa	Target protocol address
95
+ */
96
+static inline void * arp_target_pa ( struct arphdr *arphdr ) {
97
+	return ( arp_target_ha ( arphdr ) + arphdr->ar_hln );
98
+}
99
+
100
+#endif	/* _IF_ARP_H */

src/include/if_ether.h → src/include/gpxe/if_ether.h View File

@@ -1,13 +1,7 @@
1 1
 #ifndef	_IF_ETHER_H
2 2
 #define	_IF_ETHER_H
3 3
 
4
-/*
5
-   I'm moving towards the defined names in linux/if_ether.h for clarity.
6
-   The confusion between 60/64 and 1514/1518 arose because the NS8390
7
-   counts the 4 byte frame checksum in the incoming packet, but not
8
-   in the outgoing packet. 60/1514 are the correct numbers for most
9
-   if not all of the other NIC controllers.
10
-*/
4
+#include <stdint.h>
11 5
 
12 6
 #define ETH_ALEN		6	/* Size of Ethernet address */
13 7
 #define ETH_HLEN		14	/* Size of ethernet header */
@@ -24,4 +18,14 @@
24 18
 #define ETH_P_IPV6	0x86DD		/* IPv6 over blueblook */
25 19
 #define ETH_P_SLOW	0x8809		/* Ethernet slow protocols */
26 20
 
21
+/** An Ethernet link-layer header */
22
+struct ethhdr {
23
+	/** Destination MAC address */
24
+        uint8_t h_dest[ETH_ALEN];
25
+	/** Source MAC address */
26
+        uint8_t h_source[ETH_ALEN];
27
+	/** Protocol ID */
28
+        uint16_t h_protocol;
29
+} __attribute__ ((packed));
30
+
27 31
 #endif	/* _IF_ETHER_H */

+ 0
- 23
src/include/if_arp.h View File

@@ -1,23 +0,0 @@
1
-#ifndef	_IF_ARP_H
2
-#define	_IF_ARP_H
3
-
4
-#define ARP_REQUEST	1
5
-#define ARP_REPLY	2
6
-
7
-/*
8
- * A pity sipaddr and tipaddr are not longword aligned or we could use
9
- * in_addr. No, I don't want to use #pragma packed.
10
- */
11
-struct arprequest {
12
-	uint16_t hwtype;
13
-	uint16_t protocol;
14
-	uint8_t  hwlen;
15
-	uint8_t  protolen;
16
-	uint16_t opcode;
17
-	uint8_t  shwaddr[6];
18
-	uint8_t  sipaddr[4];
19
-	uint8_t  thwaddr[6];
20
-	uint8_t  tipaddr[4];
21
-} PACKED;
22
-
23
-#endif	/* _IF_ARP_H */

Loading…
Cancel
Save