|
@@ -0,0 +1,163 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+/**
|
|
20
|
+ * @file
|
|
21
|
+ *
|
|
22
|
+ * Filter streams
|
|
23
|
+ */
|
|
24
|
+
|
|
25
|
+#include <stddef.h>
|
|
26
|
+#include <gpxe/stream.h>
|
|
27
|
+#include <gpxe/filter.h>
|
|
28
|
+
|
|
29
|
+/**
|
|
30
|
+ * Connection established
|
|
31
|
+ *
|
|
32
|
+ * @v app Stream application
|
|
33
|
+ */
|
|
34
|
+void filter_connected ( struct stream_application *app ) {
|
|
35
|
+ struct filter_stream *filter =
|
|
36
|
+ container_of ( app, struct filter_stream, downstream );
|
|
37
|
+
|
|
38
|
+ stream_connected ( &filter->upstream );
|
|
39
|
+}
|
|
40
|
+
|
|
41
|
+/**
|
|
42
|
+ * Connection closed
|
|
43
|
+ *
|
|
44
|
+ * @v app Stream application
|
|
45
|
+ * @v rc Error code, if any
|
|
46
|
+ */
|
|
47
|
+void filter_closed ( struct stream_application *app, int rc ) {
|
|
48
|
+ struct filter_stream *filter =
|
|
49
|
+ container_of ( app, struct filter_stream, downstream );
|
|
50
|
+
|
|
51
|
+ stream_closed ( &filter->upstream, rc );
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+/**
|
|
55
|
+ * Transmit data
|
|
56
|
+ *
|
|
57
|
+ * @v app Stream application
|
|
58
|
+ * @v buf Temporary data buffer
|
|
59
|
+ * @v len Length of temporary data buffer
|
|
60
|
+ */
|
|
61
|
+void filter_senddata ( struct stream_application *app,
|
|
62
|
+ void *data, size_t len ) {
|
|
63
|
+ struct filter_stream *filter =
|
|
64
|
+ container_of ( app, struct filter_stream, downstream );
|
|
65
|
+
|
|
66
|
+ stream_senddata ( &filter->upstream, data, len );
|
|
67
|
+}
|
|
68
|
+
|
|
69
|
+/**
|
|
70
|
+ * Transmitted data acknowledged
|
|
71
|
+ *
|
|
72
|
+ * @v app Stream application
|
|
73
|
+ * @v len Length of acknowledged data
|
|
74
|
+ */
|
|
75
|
+void filter_acked ( struct stream_application *app, size_t len ) {
|
|
76
|
+ struct filter_stream *filter =
|
|
77
|
+ container_of ( app, struct filter_stream, downstream );
|
|
78
|
+
|
|
79
|
+ stream_acked ( &filter->upstream, len );
|
|
80
|
+}
|
|
81
|
+
|
|
82
|
+/**
|
|
83
|
+ * Receive new data
|
|
84
|
+ *
|
|
85
|
+ * @v app Stream application
|
|
86
|
+ * @v data Data
|
|
87
|
+ * @v len Length of data
|
|
88
|
+ */
|
|
89
|
+void filter_newdata ( struct stream_application *app,
|
|
90
|
+ void *data, size_t len ) {
|
|
91
|
+ struct filter_stream *filter =
|
|
92
|
+ container_of ( app, struct filter_stream, downstream );
|
|
93
|
+
|
|
94
|
+ stream_newdata ( &filter->upstream, data, len );
|
|
95
|
+}
|
|
96
|
+
|
|
97
|
+/**
|
|
98
|
+ * Bind to local address
|
|
99
|
+ *
|
|
100
|
+ * @v conn Stream connection
|
|
101
|
+ * @v local Local address
|
|
102
|
+ * @ret rc Return status code
|
|
103
|
+ */
|
|
104
|
+int filter_bind ( struct stream_connection *conn, struct sockaddr *local ) {
|
|
105
|
+ struct filter_stream *filter =
|
|
106
|
+ container_of ( conn, struct filter_stream, upstream );
|
|
107
|
+
|
|
108
|
+ return stream_bind ( &filter->downstream, local );
|
|
109
|
+}
|
|
110
|
+
|
|
111
|
+/**
|
|
112
|
+ * Connect to remote address
|
|
113
|
+ *
|
|
114
|
+ * @v conn Stream connection
|
|
115
|
+ * @v peer Remote address
|
|
116
|
+ * @ret rc Return status code
|
|
117
|
+ */
|
|
118
|
+int filter_connect ( struct stream_connection *conn, struct sockaddr *peer ) {
|
|
119
|
+ struct filter_stream *filter =
|
|
120
|
+ container_of ( conn, struct filter_stream, upstream );
|
|
121
|
+
|
|
122
|
+ return stream_connect ( &filter->downstream, peer );
|
|
123
|
+}
|
|
124
|
+
|
|
125
|
+/**
|
|
126
|
+ * Close connection
|
|
127
|
+ *
|
|
128
|
+ * @v conn Stream connection
|
|
129
|
+ */
|
|
130
|
+void filter_close ( struct stream_connection *conn ) {
|
|
131
|
+ struct filter_stream *filter =
|
|
132
|
+ container_of ( conn, struct filter_stream, upstream );
|
|
133
|
+
|
|
134
|
+ stream_close ( &filter->downstream );
|
|
135
|
+}
|
|
136
|
+
|
|
137
|
+/**
|
|
138
|
+ * Send data via connection
|
|
139
|
+ *
|
|
140
|
+ * @v conn Stream connection
|
|
141
|
+ * @v data Data to send
|
|
142
|
+ * @v len Length of data
|
|
143
|
+ * @ret rc Return status code
|
|
144
|
+ */
|
|
145
|
+int filter_send ( struct stream_connection *conn, void *data, size_t len ) {
|
|
146
|
+ struct filter_stream *filter =
|
|
147
|
+ container_of ( conn, struct filter_stream, upstream );
|
|
148
|
+
|
|
149
|
+ return stream_send ( &filter->downstream, data, len );
|
|
150
|
+}
|
|
151
|
+
|
|
152
|
+/**
|
|
153
|
+ * Notify connection that data is available to send
|
|
154
|
+ *
|
|
155
|
+ * @v conn Stream connection
|
|
156
|
+ * @ret rc Return status code
|
|
157
|
+ */
|
|
158
|
+int filter_kick ( struct stream_connection *conn ) {
|
|
159
|
+ struct filter_stream *filter =
|
|
160
|
+ container_of ( conn, struct filter_stream, upstream );
|
|
161
|
+
|
|
162
|
+ return stream_kick ( &filter->downstream );
|
|
163
|
+}
|