Browse Source

Add generic mechanism for background protocols (e.g. ARP, IGMP)

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
85a380530d
2 changed files with 99 additions and 0 deletions
  1. 47
    0
      src/core/background.c
  2. 52
    0
      src/include/background.h

+ 47
- 0
src/core/background.c View File

@@ -0,0 +1,47 @@
1
+#include "background.h"
2
+
3
+static struct background backgrounds[0] __table_start ( background );
4
+static struct background backgrounds_end[0] __table_end ( background );
5
+
6
+/** @file */
7
+
8
+/**
9
+ * Call send method of all background protocols
10
+ *
11
+ * @v timestamp		Current time
12
+ * @ret None		-
13
+ * @err None		-
14
+ *
15
+ * This calls each background protocol's background::send() method.
16
+ */
17
+void background_send ( unsigned long timestamp ) {
18
+	struct background *background;
19
+
20
+	for ( background = backgrounds ; background < backgrounds_end ;
21
+	      background++ ) {
22
+		if ( background->send )
23
+			background->send ( timestamp );
24
+	}
25
+}
26
+
27
+/**
28
+ * Call process method of all background protocols
29
+ *
30
+ * @v timestamp		Current time
31
+ * @v ptype		Packet type
32
+ * @v ip		IP header, if present
33
+ * @ret None		-
34
+ * @err None		-
35
+ *
36
+ * This calls each background protocol's background::process() method.
37
+ */
38
+void background_process ( unsigned long timestamp, unsigned short ptype,
39
+			  struct iphdr *ip ) {
40
+	struct background *background;
41
+
42
+	for ( background = backgrounds ; background < backgrounds_end ;
43
+	      background++ ) {
44
+		if ( background->process )
45
+			background->process ( timestamp, ptype, ip );
46
+	}
47
+}

+ 52
- 0
src/include/background.h View File

@@ -0,0 +1,52 @@
1
+#ifndef BACKGROUND_H
2
+#define BACKGROUND_H
3
+
4
+/** @file
5
+ *
6
+ * Background protocols
7
+ *
8
+ * Some protocols (e.g. ARP, IGMP) operate in the background; the
9
+ * upper layers are not aware of their operation.  When an ARP query
10
+ * for the local station's IP address arrives, Etherboot must reply to
11
+ * it regardless of what other operations are currently in progress.
12
+ *
13
+ * Background protocols are called in two circumstances: when
14
+ * Etherboot is about to poll for a packet, and when Etherboot has
15
+ * received a packet that the upper layer (whatever that may currently
16
+ * be) isn't interested in.
17
+ *
18
+ */
19
+
20
+#include "tables.h"
21
+#include "ip.h"
22
+
23
+/** A background protocol */
24
+struct background {
25
+	/** Send method
26
+	 *
27
+	 * This method will be called whenever Etherboot is about to
28
+	 * poll for a packet.  The background protocol should use this
29
+	 * method to send out any periodic transmissions that it may
30
+	 * require.
31
+	 */
32
+	void ( *send ) ( unsigned long timestamp );
33
+	/** Process method
34
+	 *
35
+	 * This method will be called whenever Etherboot has received
36
+	 * a packet and doesn't know what to do with it.
37
+	 */
38
+	void ( *process ) ( unsigned long timestamp, unsigned short ptype,
39
+			    struct iphdr *ip );
40
+};
41
+
42
+/** A member of the background protocols table */
43
+#define __background __table ( background, 01 )
44
+
45
+/* Functions in background.c */
46
+
47
+extern void background_send ( unsigned long timestamp );
48
+
49
+extern void background_process ( unsigned long timestamp, unsigned short ptype,
50
+				 struct iphdr *ip );
51
+
52
+#endif /* BACKGROUND_H */

Loading…
Cancel
Save