|
@@ -18,7 +18,8 @@
|
18
|
18
|
|
19
|
19
|
FILE_LICENCE ( GPL2_OR_LATER );
|
20
|
20
|
|
21
|
|
-/** Process a received TCP/IP packet
|
|
21
|
+/**
|
|
22
|
+ * Process a received TCP/IP packet
|
22
|
23
|
*
|
23
|
24
|
* @v iobuf I/O buffer
|
24
|
25
|
* @v netdev Network device
|
|
@@ -57,7 +58,27 @@ int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
|
57
|
58
|
return -EPROTONOSUPPORT;
|
58
|
59
|
}
|
59
|
60
|
|
60
|
|
-/** Transmit a TCP/IP packet
|
|
61
|
+/**
|
|
62
|
+ * Find TCP/IP network-layer protocol
|
|
63
|
+ *
|
|
64
|
+ * @v st_dest Destination address
|
|
65
|
+ * @ret tcpip_net TCP/IP network-layer protocol, or NULL if not found
|
|
66
|
+ */
|
|
67
|
+static struct tcpip_net_protocol *
|
|
68
|
+tcpip_net_protocol ( struct sockaddr_tcpip *st_dest ) {
|
|
69
|
+ struct tcpip_net_protocol *tcpip_net;
|
|
70
|
+
|
|
71
|
+ for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
|
|
72
|
+ if ( tcpip_net->sa_family == st_dest->st_family )
|
|
73
|
+ return tcpip_net;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family );
|
|
77
|
+ return NULL;
|
|
78
|
+}
|
|
79
|
+
|
|
80
|
+/**
|
|
81
|
+ * Transmit a TCP/IP packet
|
61
|
82
|
*
|
62
|
83
|
* @v iobuf I/O buffer
|
63
|
84
|
* @v tcpip_protocol Transport-layer protocol
|
|
@@ -73,19 +94,34 @@ int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol,
|
73
|
94
|
struct tcpip_net_protocol *tcpip_net;
|
74
|
95
|
|
75
|
96
|
/* Hand off packet to the appropriate network-layer protocol */
|
76
|
|
- for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
|
77
|
|
- if ( tcpip_net->sa_family == st_dest->st_family ) {
|
78
|
|
- DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
|
79
|
|
- return tcpip_net->tx ( iobuf, tcpip_protocol, st_src,
|
80
|
|
- st_dest, netdev, trans_csum );
|
81
|
|
- }
|
|
97
|
+ tcpip_net = tcpip_net_protocol ( st_dest );
|
|
98
|
+ if ( tcpip_net ) {
|
|
99
|
+ DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
|
|
100
|
+ return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, st_dest,
|
|
101
|
+ netdev, trans_csum );
|
82
|
102
|
}
|
83
|
|
-
|
84
|
|
- DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family );
|
|
103
|
+
|
85
|
104
|
free_iob ( iobuf );
|
86
|
105
|
return -EAFNOSUPPORT;
|
87
|
106
|
}
|
88
|
107
|
|
|
108
|
+/**
|
|
109
|
+ * Determine transmitting network device
|
|
110
|
+ *
|
|
111
|
+ * @v st_dest Destination address
|
|
112
|
+ * @ret netdev Network device, or NULL
|
|
113
|
+ */
|
|
114
|
+struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest ) {
|
|
115
|
+ struct tcpip_net_protocol *tcpip_net;
|
|
116
|
+
|
|
117
|
+ /* Hand off to the appropriate network-layer protocol */
|
|
118
|
+ tcpip_net = tcpip_net_protocol ( st_dest );
|
|
119
|
+ if ( tcpip_net )
|
|
120
|
+ return tcpip_net->netdev ( st_dest );
|
|
121
|
+
|
|
122
|
+ return NULL;
|
|
123
|
+}
|
|
124
|
+
|
89
|
125
|
/**
|
90
|
126
|
* Calculate continued TCP/IP checkum
|
91
|
127
|
*
|