Переглянути джерело

[interface] Convert all data-xfer interfaces to generic interfaces

Remove data-xfer as an interface type, and replace data-xfer
interfaces with generic interfaces supporting the data-xfer methods.

Filter interfaces (as used by the TLS layer) are handled using the
generic pass-through interface capability.  A side-effect of this is
that deliver_raw() no longer exists as a data-xfer method.  (In
practice this doesn't lose any efficiency, since there are no
instances within the current codebase where xfer_deliver_raw() is used
to pass data to an interface supporting the deliver_raw() method.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 роки тому
джерело
коміт
4327d5d39f

+ 42
- 50
src/arch/i386/interface/pxe/pxe_tftp.c Переглянути файл

@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
31 31
 #include <ipxe/uaccess.h>
32 32
 #include <ipxe/in.h>
33 33
 #include <ipxe/tftp.h>
34
+#include <ipxe/iobuf.h>
34 35
 #include <ipxe/xfer.h>
35 36
 #include <ipxe/open.h>
36 37
 #include <ipxe/process.h>
@@ -39,7 +40,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
39 40
 /** A PXE TFTP connection */
40 41
 struct pxe_tftp_connection {
41 42
 	/** Data transfer interface */
42
-	struct xfer_interface xfer;
43
+	struct interface xfer;
43 44
 	/** Data buffer */
44 45
 	userptr_t buffer;
45 46
 	/** Size of data buffer */
@@ -58,93 +59,84 @@ struct pxe_tftp_connection {
58 59
 	int rc;
59 60
 };
60 61
 
61
-/** The PXE TFTP connection */
62
-static struct pxe_tftp_connection pxe_tftp = {
63
-	.xfer = XFER_INIT ( &null_xfer_ops ),
64
-};
65
-
66 62
 /**
67 63
  * Close PXE TFTP connection
68 64
  *
65
+ * @v pxe_tftp		PXE TFTP connection
69 66
  * @v rc		Final status code
70 67
  */
71
-static void pxe_tftp_close ( int rc ) {
72
-	xfer_nullify ( &pxe_tftp.xfer );
73
-	xfer_close ( &pxe_tftp.xfer, rc );
74
-	pxe_tftp.rc = rc;
68
+static void pxe_tftp_close ( struct pxe_tftp_connection *pxe_tftp, int rc ) {
69
+	intf_shutdown ( &pxe_tftp->xfer, rc );
70
+	pxe_tftp->rc = rc;
75 71
 }
76 72
 
77 73
 /**
78 74
  * Receive new data
79 75
  *
80
- * @v xfer		Data transfer interface
76
+ * @v pxe_tftp		PXE TFTP connection
81 77
  * @v iobuf		I/O buffer
82 78
  * @v meta		Transfer metadata
83 79
  * @ret rc		Return status code
84 80
  */
85
-static int pxe_tftp_xfer_deliver_iob ( struct xfer_interface *xfer __unused,
86
-				       struct io_buffer *iobuf,
87
-				       struct xfer_metadata *meta ) {
81
+static int pxe_tftp_xfer_deliver ( struct pxe_tftp_connection *pxe_tftp,
82
+				   struct io_buffer *iobuf,
83
+				   struct xfer_metadata *meta ) {
88 84
 	size_t len = iob_len ( iobuf );
89 85
 	int rc = 0;
90 86
 
91 87
 	/* Calculate new buffer position */
92 88
 	if ( meta->whence != SEEK_CUR )
93
-		pxe_tftp.offset = 0;
94
-	pxe_tftp.offset += meta->offset;
89
+		pxe_tftp->offset = 0;
90
+	pxe_tftp->offset += meta->offset;
95 91
 
96 92
 	/* Copy data block to buffer */
97 93
 	if ( len == 0 ) {
98 94
 		/* No data (pure seek); treat as success */
99
-	} else if ( pxe_tftp.offset < pxe_tftp.start ) {
95
+	} else if ( pxe_tftp->offset < pxe_tftp->start ) {
100 96
 		DBG ( " buffer underrun at %zx (min %zx)",
101
-		      pxe_tftp.offset, pxe_tftp.start );
97
+		      pxe_tftp->offset, pxe_tftp->start );
102 98
 		rc = -ENOBUFS;
103
-	} else if ( ( pxe_tftp.offset + len ) >
104
-		    ( pxe_tftp.start + pxe_tftp.size ) ) {
99
+	} else if ( ( pxe_tftp->offset + len ) >
100
+		    ( pxe_tftp->start + pxe_tftp->size ) ) {
105 101
 		DBG ( " buffer overrun at %zx (max %zx)",
106
-		      ( pxe_tftp.offset + len ),
107
-		      ( pxe_tftp.start + pxe_tftp.size ) );
102
+		      ( pxe_tftp->offset + len ),
103
+		      ( pxe_tftp->start + pxe_tftp->size ) );
108 104
 		rc = -ENOBUFS;
109 105
 	} else {
110
-		copy_to_user ( pxe_tftp.buffer,
111
-			       ( pxe_tftp.offset - pxe_tftp.start ),
106
+		copy_to_user ( pxe_tftp->buffer,
107
+			       ( pxe_tftp->offset - pxe_tftp->start ),
112 108
 			       iobuf->data, len );
113 109
 	}
114 110
 
115 111
 	/* Calculate new buffer position */
116
-	pxe_tftp.offset += len;
112
+	pxe_tftp->offset += len;
117 113
 
118 114
 	/* Record maximum offset as the file size */
119
-	if ( pxe_tftp.max_offset < pxe_tftp.offset )
120
-		pxe_tftp.max_offset = pxe_tftp.offset;
115
+	if ( pxe_tftp->max_offset < pxe_tftp->offset )
116
+		pxe_tftp->max_offset = pxe_tftp->offset;
121 117
 
122 118
 	/* Terminate transfer on error */
123 119
 	if ( rc != 0 )
124
-		pxe_tftp_close ( rc );
120
+		pxe_tftp_close ( pxe_tftp, rc );
125 121
 
126 122
 	free_iob ( iobuf );
127 123
 	return rc;
128 124
 }
129 125
 
130
-/**
131
- * Handle close() event
132
- *
133
- * @v xfer		Data transfer interface
134
- * @v rc		Reason for close
135
- */
136
-static void pxe_tftp_xfer_close ( struct xfer_interface *xfer __unused,
137
-				  int rc ) {
138
-	pxe_tftp_close ( rc );
139
-}
126
+/** PXE TFTP connection interface operations */
127
+static struct interface_operation pxe_tftp_xfer_ops[] = {
128
+	INTF_OP ( xfer_deliver, struct pxe_tftp_connection *,
129
+		  pxe_tftp_xfer_deliver ),
130
+	INTF_OP ( intf_close, struct pxe_tftp_connection *, pxe_tftp_close ),
131
+};
140 132
 
141
-static struct xfer_interface_operations pxe_tftp_xfer_ops = {
142
-	.close		= pxe_tftp_xfer_close,
143
-	.vredirect	= xfer_vreopen,
144
-	.window		= unlimited_xfer_window,
145
-	.alloc_iob	= default_xfer_alloc_iob,
146
-	.deliver_iob	= pxe_tftp_xfer_deliver_iob,
147
-	.deliver_raw	= xfer_deliver_as_iob,
133
+/** PXE TFTP connection interface descriptor */
134
+static struct interface_descriptor pxe_tftp_xfer_desc =
135
+	INTF_DESC ( struct pxe_tftp_connection, xfer, pxe_tftp_xfer_ops );
136
+
137
+/** The PXE TFTP connection */
138
+static struct pxe_tftp_connection pxe_tftp = {
139
+	.xfer = INTF_INIT ( pxe_tftp_xfer_desc ),
148 140
 };
149 141
 
150 142
 /**
@@ -173,7 +165,7 @@ static int pxe_tftp_open ( uint32_t ipaddress, unsigned int port,
173 165
 
174 166
 	/* Reset PXE TFTP connection structure */
175 167
 	memset ( &pxe_tftp, 0, sizeof ( pxe_tftp ) );
176
-	xfer_init ( &pxe_tftp.xfer, &pxe_tftp_xfer_ops, NULL );
168
+	intf_init ( &pxe_tftp.xfer, &pxe_tftp_xfer_desc, NULL );
177 169
 	pxe_tftp.rc = -EINPROGRESS;
178 170
 
179 171
 	/* Construct URI string */
@@ -247,7 +239,7 @@ PXENV_EXIT_t pxenv_tftp_open ( struct s_PXENV_TFTP_OPEN *tftp_open ) {
247 239
 	DBG ( "PXENV_TFTP_OPEN" );
248 240
 
249 241
 	/* Guard against callers that fail to close before re-opening */
250
-	pxe_tftp_close ( 0 );
242
+	pxe_tftp_close ( &pxe_tftp, 0 );
251 243
 
252 244
 	/* Open connection */
253 245
 	if ( ( rc = pxe_tftp_open ( tftp_open->ServerIPAddress,
@@ -296,7 +288,7 @@ PXENV_EXIT_t pxenv_tftp_open ( struct s_PXENV_TFTP_OPEN *tftp_open ) {
296 288
 PXENV_EXIT_t pxenv_tftp_close ( struct s_PXENV_TFTP_CLOSE *tftp_close ) {
297 289
 	DBG ( "PXENV_TFTP_CLOSE" );
298 290
 
299
-	pxe_tftp_close ( 0 );
291
+	pxe_tftp_close ( &pxe_tftp, 0 );
300 292
 	tftp_close->Status = PXENV_STATUS_SUCCESS;
301 293
 	return PXENV_EXIT_SUCCESS;
302 294
 }
@@ -491,7 +483,7 @@ PXENV_EXIT_t pxenv_tftp_read_file ( struct s_PXENV_TFTP_READ_FILE
491 483
 	tftp_read_file->BufferSize = pxe_tftp.max_offset;
492 484
 
493 485
 	/* Close TFTP file */
494
-	pxe_tftp_close ( rc );
486
+	pxe_tftp_close ( &pxe_tftp, rc );
495 487
 
496 488
 	tftp_read_file->Status = PXENV_STATUS ( rc );
497 489
 	return ( rc ? PXENV_EXIT_FAILURE : PXENV_EXIT_SUCCESS );
@@ -565,7 +557,7 @@ PXENV_EXIT_t pxenv_tftp_get_fsize ( struct s_PXENV_TFTP_GET_FSIZE
565 557
 		rc = 0;
566 558
 
567 559
 	/* Close TFTP file */
568
-	pxe_tftp_close ( rc );
560
+	pxe_tftp_close ( &pxe_tftp, rc );
569 561
 
570 562
 	tftp_get_fsize->Status = PXENV_STATUS ( rc );
571 563
 	return ( rc ? PXENV_EXIT_FAILURE : PXENV_EXIT_SUCCESS );

+ 16
- 19
src/arch/i386/interface/pxe/pxe_udp.c Переглянути файл

@@ -6,6 +6,7 @@
6 6
 
7 7
 #include <string.h>
8 8
 #include <byteswap.h>
9
+#include <ipxe/iobuf.h>
9 10
 #include <ipxe/xfer.h>
10 11
 #include <ipxe/udp.h>
11 12
 #include <ipxe/uaccess.h>
@@ -35,7 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 36
 /** A PXE UDP connection */
36 37
 struct pxe_udp_connection {
37 38
 	/** Data transfer interface to UDP stack */
38
-	struct xfer_interface xfer;
39
+	struct interface xfer;
39 40
 	/** Local address */
40 41
 	struct sockaddr_in local;
41 42
 	/** Current PXENV_UDP_READ parameter block */
@@ -45,7 +46,7 @@ struct pxe_udp_connection {
45 46
 /**
46 47
  * Receive PXE UDP data
47 48
  *
48
- * @v xfer			Data transfer interface
49
+ * @v pxe_udp			PXE UDP connection
49 50
  * @v iobuf			I/O buffer
50 51
  * @v meta			Data transfer metadata
51 52
  * @ret rc			Return status code
@@ -53,11 +54,9 @@ struct pxe_udp_connection {
53 54
  * Receives a packet as part of the current pxenv_udp_read()
54 55
  * operation.
55 56
  */
56
-static int pxe_udp_deliver_iob ( struct xfer_interface *xfer,
57
-				 struct io_buffer *iobuf,
58
-				 struct xfer_metadata *meta ) {
59
-	struct pxe_udp_connection *pxe_udp = 
60
-		container_of ( xfer, struct pxe_udp_connection, xfer );
57
+static int pxe_udp_deliver ( struct pxe_udp_connection *pxe_udp,
58
+			     struct io_buffer *iobuf,
59
+			     struct xfer_metadata *meta ) {
61 60
 	struct s_PXENV_UDP_READ *pxenv_udp_read = pxe_udp->pxenv_udp_read;
62 61
 	struct sockaddr_in *sin_src;
63 62
 	struct sockaddr_in *sin_dest;
@@ -102,18 +101,17 @@ static int pxe_udp_deliver_iob ( struct xfer_interface *xfer,
102 101
 }
103 102
 
104 103
 /** PXE UDP data transfer interface operations */
105
-static struct xfer_interface_operations pxe_udp_xfer_operations = {
106
-	.close		= ignore_xfer_close,
107
-	.vredirect	= ignore_xfer_vredirect,
108
-	.window		= unlimited_xfer_window,
109
-	.alloc_iob	= default_xfer_alloc_iob,
110
-	.deliver_iob	= pxe_udp_deliver_iob,
111
-	.deliver_raw	= xfer_deliver_as_iob,
104
+static struct interface_operation pxe_udp_xfer_operations[] = {
105
+	INTF_OP ( xfer_deliver, struct pxe_udp_connection *, pxe_udp_deliver ),
112 106
 };
113 107
 
108
+/** PXE UDP data transfer interface descriptor */
109
+static struct interface_descriptor pxe_udp_xfer_desc =
110
+	INTF_DESC ( struct pxe_udp_connection, xfer, pxe_udp_xfer_operations );
111
+
114 112
 /** The PXE UDP connection */
115 113
 static struct pxe_udp_connection pxe_udp = {
116
-	.xfer = XFER_INIT ( &pxe_udp_xfer_operations ),
114
+	.xfer = INTF_INIT ( pxe_udp_xfer_desc ),
117 115
 	.local = {
118 116
 		.sin_family = AF_INET,
119 117
 	},
@@ -171,7 +169,7 @@ PXENV_EXIT_t pxenv_udp_open ( struct s_PXENV_UDP_OPEN *pxenv_udp_open ) {
171 169
 	DBG ( " %s", inet_ntoa ( pxe_udp.local.sin_addr ) );
172 170
 
173 171
 	/* Open promiscuous UDP connection */
174
-	xfer_close ( &pxe_udp.xfer, 0 );
172
+	intf_restart ( &pxe_udp.xfer, 0 );
175 173
 	if ( ( rc = udp_open_promisc ( &pxe_udp.xfer ) ) != 0 ) {
176 174
 		pxenv_udp_open->Status = PXENV_STATUS ( rc );
177 175
 		return PXENV_EXIT_FAILURE;
@@ -206,7 +204,7 @@ PXENV_EXIT_t pxenv_udp_close ( struct s_PXENV_UDP_CLOSE *pxenv_udp_close ) {
206 204
 	DBG ( "PXENV_UDP_CLOSE" );
207 205
 
208 206
 	/* Close UDP connection */
209
-	xfer_close ( &pxe_udp.xfer, 0 );
207
+	intf_restart ( &pxe_udp.xfer, 0 );
210 208
 
211 209
 	pxenv_udp_close->Status = PXENV_STATUS_SUCCESS;
212 210
 	return PXENV_EXIT_SUCCESS;
@@ -304,8 +302,7 @@ PXENV_EXIT_t pxenv_udp_write ( struct s_PXENV_UDP_WRITE *pxenv_udp_write ) {
304 302
 	      ntohs ( pxenv_udp_write->dst_port ) );
305 303
 	
306 304
 	/* Transmit packet */
307
-	if ( ( rc = xfer_deliver_iob_meta ( &pxe_udp.xfer, iobuf,
308
-					    &meta ) ) != 0 ) {
305
+	if ( ( rc = xfer_deliver ( &pxe_udp.xfer, iobuf, &meta ) ) != 0 ) {
309 306
 		pxenv_udp_write->Status = PXENV_STATUS ( rc );
310 307
 		return PXENV_EXIT_FAILURE;
311 308
 	}

+ 16
- 32
src/core/downloader.c Переглянути файл

@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
21 21
 #include <stdlib.h>
22 22
 #include <stdarg.h>
23 23
 #include <errno.h>
24
+#include <ipxe/iobuf.h>
24 25
 #include <ipxe/xfer.h>
25 26
 #include <ipxe/open.h>
26 27
 #include <ipxe/job.h>
@@ -43,7 +44,7 @@ struct downloader {
43 44
 	/** Job control interface */
44 45
 	struct interface job;
45 46
 	/** Data transfer interface */
46
-	struct xfer_interface xfer;
47
+	struct interface xfer;
47 48
 
48 49
 	/** Image to contain downloaded file */
49 50
 	struct image *image;
@@ -79,8 +80,7 @@ static void downloader_finished ( struct downloader *downloader, int rc ) {
79 80
 		rc = downloader->register_image ( downloader->image );
80 81
 
81 82
 	/* Shut down interfaces */
82
-	xfer_nullify ( &downloader->xfer );
83
-	xfer_close ( &downloader->xfer, rc );
83
+	intf_shutdown ( &downloader->xfer, rc );
84 84
 	intf_shutdown ( &downloader->job, rc );
85 85
 }
86 86
 
@@ -145,18 +145,16 @@ static void downloader_progress ( struct downloader *downloader,
145 145
  */
146 146
 
147 147
 /**
148
- * Handle deliver_raw() event received via data transfer interface
148
+ * Handle received data
149 149
  *
150
- * @v xfer		Downloader data transfer interface
150
+ * @v downloader	Downloader
151 151
  * @v iobuf		Datagram I/O buffer
152 152
  * @v meta		Data transfer metadata
153 153
  * @ret rc		Return status code
154 154
  */
155
-static int downloader_xfer_deliver_iob ( struct xfer_interface *xfer,
156
-					 struct io_buffer *iobuf,
157
-					 struct xfer_metadata *meta ) {
158
-	struct downloader *downloader =
159
-		container_of ( xfer, struct downloader, xfer );
155
+static int downloader_xfer_deliver ( struct downloader *downloader,
156
+				     struct io_buffer *iobuf,
157
+				     struct xfer_metadata *meta ) {
160 158
 	size_t len;
161 159
 	size_t max;
162 160
 	int rc;
@@ -184,30 +182,16 @@ static int downloader_xfer_deliver_iob ( struct xfer_interface *xfer,
184 182
 	return rc;
185 183
 }
186 184
 
187
-/**
188
- * Handle close() event received via data transfer interface
189
- *
190
- * @v xfer		Downloader data transfer interface
191
- * @v rc		Reason for close
192
- */
193
-static void downloader_xfer_close ( struct xfer_interface *xfer, int rc ) {
194
-	struct downloader *downloader =
195
-		container_of ( xfer, struct downloader, xfer );
196
-
197
-	/* Terminate download */
198
-	downloader_finished ( downloader, rc );
199
-}
200
-
201 185
 /** Downloader data transfer interface operations */
202
-static struct xfer_interface_operations downloader_xfer_operations = {
203
-	.close		= downloader_xfer_close,
204
-	.vredirect	= xfer_vreopen,
205
-	.window		= unlimited_xfer_window,
206
-	.alloc_iob	= default_xfer_alloc_iob,
207
-	.deliver_iob	= downloader_xfer_deliver_iob,
208
-	.deliver_raw	= xfer_deliver_as_iob,
186
+static struct interface_operation downloader_xfer_operations[] = {
187
+	INTF_OP ( xfer_deliver, struct downloader *, downloader_xfer_deliver ),
188
+	INTF_OP ( intf_close, struct downloader *, downloader_finished ),
209 189
 };
210 190
 
191
+/** Downloader data transfer interface descriptor */
192
+static struct interface_descriptor downloader_xfer_desc =
193
+	INTF_DESC ( struct downloader, xfer, downloader_xfer_operations );
194
+
211 195
 /****************************************************************************
212 196
  *
213 197
  * Job control interface
@@ -258,7 +242,7 @@ int create_downloader ( struct interface *job, struct image *image,
258 242
 	ref_init ( &downloader->refcnt, downloader_free );
259 243
 	intf_init ( &downloader->job, &downloader_job_desc,
260 244
 		    &downloader->refcnt );
261
-	xfer_init ( &downloader->xfer, &downloader_xfer_operations,
245
+	intf_init ( &downloader->xfer, &downloader_xfer_desc,
262 246
 		    &downloader->refcnt );
263 247
 	downloader->image = image_get ( image );
264 248
 	downloader->register_image = register_image;

+ 0
- 74
src/core/filter.c Переглянути файл

@@ -1,74 +0,0 @@
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
-FILE_LICENCE ( GPL2_OR_LATER );
20
-
21
-#include <ipxe/xfer.h>
22
-#include <ipxe/filter.h>
23
-
24
-/** @file
25
- *
26
- * Data transfer filters
27
- *
28
- */
29
-
30
-/*
31
- * Pass-through methods to be used by filters which don't want to
32
- * intercept all events.
33
- *
34
- */
35
-
36
-void filter_close ( struct xfer_interface *xfer, int rc ) {
37
-	struct xfer_interface *other = filter_other_half ( xfer );
38
-
39
-	xfer_close ( other, rc );
40
-}
41
-
42
-int filter_vredirect ( struct xfer_interface *xfer, int type,
43
-			va_list args ) {
44
-	struct xfer_interface *other = filter_other_half ( xfer );
45
-
46
-	return xfer_vredirect ( other, type, args );
47
-}
48
-
49
-size_t filter_window ( struct xfer_interface *xfer ) {
50
-	struct xfer_interface *other = filter_other_half ( xfer );
51
-
52
-	return xfer_window ( other );
53
-}
54
-
55
-struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
56
-				      size_t len ) {
57
-	struct xfer_interface *other = filter_other_half ( xfer );
58
-
59
-	return xfer_alloc_iob ( other, len );
60
-}
61
-
62
-int filter_deliver_iob ( struct xfer_interface *xfer, struct io_buffer *iobuf,
63
-			 struct xfer_metadata *meta ) {
64
-	struct xfer_interface *other = filter_other_half ( xfer );
65
-
66
-	return xfer_deliver_iob_meta ( other, iobuf, meta );
67
-}
68
-
69
-int filter_deliver_raw ( struct xfer_interface *xfer, const void *data,
70
-			 size_t len ) {
71
-	struct xfer_interface *other = filter_other_half ( xfer );
72
-
73
-	return xfer_deliver_raw ( other, data, len );
74
-}

+ 10
- 19
src/core/hw.c Переглянути файл

@@ -15,33 +15,24 @@
15 15
 
16 16
 struct hw {
17 17
 	struct refcnt refcnt;
18
-	struct xfer_interface xfer;
18
+	struct interface xfer;
19 19
 	struct process process;
20 20
 };
21 21
 
22 22
 static const char hw_msg[] = "Hello world!\n";
23 23
 
24 24
 static void hw_finished ( struct hw *hw, int rc ) {
25
-	xfer_nullify ( &hw->xfer );
26
-	xfer_close ( &hw->xfer, rc );
25
+	intf_shutdown ( &hw->xfer, rc );
27 26
 	process_del ( &hw->process );
28 27
 }
29 28
 
30
-static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
31
-	struct hw *hw = container_of ( xfer, struct hw, xfer );
32
-
33
-	hw_finished ( hw, rc );
34
-}
35
-
36
-static struct xfer_interface_operations hw_xfer_operations = {
37
-	.close		= hw_xfer_close,
38
-	.vredirect	= ignore_xfer_vredirect,
39
-	.window		= unlimited_xfer_window,
40
-	.alloc_iob	= default_xfer_alloc_iob,
41
-	.deliver_iob	= xfer_deliver_as_raw,
42
-	.deliver_raw	= ignore_xfer_deliver_raw,
29
+static struct interface_operation hw_xfer_operations[] = {
30
+	INTF_OP ( intf_close, struct hw *, hw_finished ),
43 31
 };
44 32
 
33
+static struct interface_descriptor hw_xfer_desc =
34
+	INTF_DESC ( struct hw, xfer, hw_xfer_operations );
35
+
45 36
 static void hw_step ( struct process *process ) {
46 37
 	struct hw *hw = container_of ( process, struct hw, process );
47 38
 	int rc;
@@ -52,7 +43,7 @@ static void hw_step ( struct process *process ) {
52 43
 	}
53 44
 }
54 45
 
55
-static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
46
+static int hw_open ( struct interface *xfer, struct uri *uri __unused ) {
56 47
 	struct hw *hw;
57 48
 
58 49
 	/* Allocate and initialise structure */
@@ -60,11 +51,11 @@ static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
60 51
 	if ( ! hw )
61 52
 		return -ENOMEM;
62 53
 	ref_init ( &hw->refcnt, NULL );
63
-	xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
54
+	intf_init ( &hw->xfer, &hw_xfer_desc, &hw->refcnt );
64 55
 	process_init ( &hw->process, hw_step, &hw->refcnt );
65 56
 
66 57
 	/* Attach parent interface, mortalise self, and return */
67
-	xfer_plug_plug ( &hw->xfer, xfer );
58
+	intf_plug_plug ( &hw->xfer, xfer );
68 59
 	ref_put ( &hw->refcnt );
69 60
 	return 0;
70 61
 }

+ 37
- 32
src/core/open.c Переглянути файл

@@ -35,14 +35,14 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 35
 /**
36 36
  * Open URI
37 37
  *
38
- * @v xfer		Data transfer interface
38
+ * @v intf		Data transfer interface
39 39
  * @v uri		URI
40 40
  * @ret rc		Return status code
41 41
  *
42 42
  * The URI will be regarded as being relative to the current working
43 43
  * URI (see churi()).
44 44
  */
45
-int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
45
+int xfer_open_uri ( struct interface *intf, struct uri *uri ) {
46 46
 	struct uri_opener *opener;
47 47
 	struct uri *resolved_uri;
48 48
 	int rc = -ENOTSUP;
@@ -55,14 +55,16 @@ int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
55 55
 	/* Find opener which supports this URI scheme */
56 56
 	for_each_table_entry ( opener, URI_OPENERS ) {
57 57
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
58
-			DBGC ( xfer, "XFER %p opening %s URI\n",
59
-			       xfer, opener->scheme );
60
-			rc = opener->open ( xfer, resolved_uri );
58
+			DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT
59
+			       " opening %s URI\n", INTF_DBG ( intf ),
60
+			       resolved_uri->scheme );
61
+			rc = opener->open ( intf, resolved_uri );
61 62
 			goto done;
62 63
 		}
63 64
 	}
64
-	DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
65
-	       "\"%s\"\n", xfer, resolved_uri->scheme );
65
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
66
+	       "unsupported URI scheme \"%s\"\n",
67
+	       INTF_DBG ( intf ), resolved_uri->scheme );
66 68
 
67 69
  done:
68 70
 	uri_put ( resolved_uri );
@@ -72,25 +74,26 @@ int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
72 74
 /**
73 75
  * Open URI string
74 76
  *
75
- * @v xfer		Data transfer interface
77
+ * @v intf		Data transfer interface
76 78
  * @v uri_string	URI string (e.g. "http://ipxe.org/kernel")
77 79
  * @ret rc		Return status code
78 80
  *
79 81
  * The URI will be regarded as being relative to the current working
80 82
  * URI (see churi()).
81 83
  */
82
-int xfer_open_uri_string ( struct xfer_interface *xfer,
84
+int xfer_open_uri_string ( struct interface *intf,
83 85
 			   const char *uri_string ) {
84 86
 	struct uri *uri;
85 87
 	int rc;
86 88
 
87
-	DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
89
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening URI %s\n",
90
+	       INTF_DBG ( intf ), uri_string );
88 91
 
89 92
 	uri = parse_uri ( uri_string );
90 93
 	if ( ! uri )
91 94
 		return -ENOMEM;
92 95
 
93
-	rc = xfer_open_uri ( xfer, uri );
96
+	rc = xfer_open_uri ( intf, uri );
94 97
 
95 98
 	uri_put ( uri );
96 99
 	return rc;
@@ -99,29 +102,30 @@ int xfer_open_uri_string ( struct xfer_interface *xfer,
99 102
 /**
100 103
  * Open socket
101 104
  *
102
- * @v xfer		Data transfer interface
105
+ * @v intf		Data transfer interface
103 106
  * @v semantics		Communication semantics (e.g. SOCK_STREAM)
104 107
  * @v peer		Peer socket address
105 108
  * @v local		Local socket address, or NULL
106 109
  * @ret rc		Return status code
107 110
  */
108
-int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
111
+int xfer_open_socket ( struct interface *intf, int semantics,
109 112
 		       struct sockaddr *peer, struct sockaddr *local ) {
110 113
 	struct socket_opener *opener;
111 114
 
112
-	DBGC ( xfer, "XFER %p opening (%s,%s) socket\n", xfer,
113
-	       socket_semantics_name ( semantics ),
115
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening (%s,%s) socket\n",
116
+	       INTF_DBG ( intf ), socket_semantics_name ( semantics ),
114 117
 	       socket_family_name ( peer->sa_family ) );
115 118
 
116 119
 	for_each_table_entry ( opener, SOCKET_OPENERS ) {
117 120
 		if ( ( opener->semantics == semantics ) &&
118 121
 		     ( opener->family == peer->sa_family ) ) {
119
-			return opener->open ( xfer, peer, local );
122
+			return opener->open ( intf, peer, local );
120 123
 		}
121 124
 	}
122 125
 
123
-	DBGC ( xfer, "XFER %p attempted to open unsupported socket type "
124
-	       "(%s,%s)\n", xfer, socket_semantics_name ( semantics ),
126
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
127
+	       "unsupported socket type (%s,%s)\n",
128
+	       INTF_DBG ( intf ), socket_semantics_name ( semantics ),
125 129
 	       socket_family_name ( peer->sa_family ) );
126 130
 	return -ENOTSUP;
127 131
 }
@@ -129,30 +133,31 @@ int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
129 133
 /**
130 134
  * Open location
131 135
  *
132
- * @v xfer		Data transfer interface
136
+ * @v intf		Data transfer interface
133 137
  * @v type		Location type
134 138
  * @v args		Remaining arguments depend upon location type
135 139
  * @ret rc		Return status code
136 140
  */
137
-int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args ) {
141
+int xfer_vopen ( struct interface *intf, int type, va_list args ) {
138 142
 	switch ( type ) {
139 143
 	case LOCATION_URI_STRING: {
140 144
 		const char *uri_string = va_arg ( args, const char * );
141 145
 
142
-		return xfer_open_uri_string ( xfer, uri_string ); }
146
+		return xfer_open_uri_string ( intf, uri_string ); }
143 147
 	case LOCATION_URI: {
144 148
 		struct uri *uri = va_arg ( args, struct uri * );
145 149
 
146
-		return xfer_open_uri ( xfer, uri ); }
150
+		return xfer_open_uri ( intf, uri ); }
147 151
 	case LOCATION_SOCKET: {
148 152
 		int semantics = va_arg ( args, int );
149 153
 		struct sockaddr *peer = va_arg ( args, struct sockaddr * );
150 154
 		struct sockaddr *local = va_arg ( args, struct sockaddr * );
151 155
 
152
-		return xfer_open_socket ( xfer, semantics, peer, local ); }
156
+		return xfer_open_socket ( intf, semantics, peer, local ); }
153 157
 	default:
154
-		DBGC ( xfer, "XFER %p attempted to open unsupported location "
155
-		       "type %d\n", xfer, type );
158
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to "
159
+		       "open unsupported location type %d\n",
160
+		       INTF_DBG ( intf ), type );
156 161
 		return -ENOTSUP;
157 162
 	}
158 163
 }
@@ -160,17 +165,17 @@ int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args ) {
160 165
 /**
161 166
  * Open location
162 167
  *
163
- * @v xfer		Data transfer interface
168
+ * @v intf		Data transfer interface
164 169
  * @v type		Location type
165 170
  * @v ...		Remaining arguments depend upon location type
166 171
  * @ret rc		Return status code
167 172
  */
168
-int xfer_open ( struct xfer_interface *xfer, int type, ... ) {
173
+int xfer_open ( struct interface *intf, int type, ... ) {
169 174
 	va_list args;
170 175
 	int rc;
171 176
 
172 177
 	va_start ( args, type );
173
-	rc = xfer_vopen ( xfer, type, args );
178
+	rc = xfer_vopen ( intf, type, args );
174 179
 	va_end ( args );
175 180
 	return rc;
176 181
 }
@@ -178,7 +183,7 @@ int xfer_open ( struct xfer_interface *xfer, int type, ... ) {
178 183
 /**
179 184
  * Reopen location
180 185
  *
181
- * @v xfer		Data transfer interface
186
+ * @v intf		Data transfer interface
182 187
  * @v type		Location type
183 188
  * @v args		Remaining arguments depend upon location type
184 189
  * @ret rc		Return status code
@@ -187,11 +192,11 @@ int xfer_open ( struct xfer_interface *xfer, int type, ... ) {
187 192
  * using xfer_vopen().  It is intended to be used as a .vredirect
188 193
  * method handler.
189 194
  */
190
-int xfer_vreopen ( struct xfer_interface *xfer, int type, va_list args ) {
195
+int xfer_vreopen ( struct interface *intf, int type, va_list args ) {
191 196
 
192 197
 	/* Close existing connection */
193
-	xfer_close ( xfer, 0 );
198
+	intf_restart ( intf, 0 );
194 199
 
195 200
 	/* Open new location */
196
-	return xfer_vopen ( xfer, type, args );
201
+	return xfer_vopen ( intf, type, args );
197 202
 }

+ 15
- 32
src/core/posix_io.c Переглянути файл

@@ -22,6 +22,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
22 22
 #include <string.h>
23 23
 #include <errno.h>
24 24
 #include <ipxe/list.h>
25
+#include <ipxe/iobuf.h>
25 26
 #include <ipxe/xfer.h>
26 27
 #include <ipxe/open.h>
27 28
 #include <ipxe/process.h>
@@ -50,7 +51,7 @@ struct posix_file {
50 51
 	 */
51 52
 	int rc;
52 53
 	/** Data transfer interface */
53
-	struct xfer_interface xfer;
54
+	struct interface xfer;
54 55
 	/** Current seek position */
55 56
 	size_t pos;
56 57
 	/** File size */
@@ -87,38 +88,21 @@ static void posix_file_free ( struct refcnt *refcnt ) {
87 88
  * @v rc		Reason for termination
88 89
  */
89 90
 static void posix_file_finished ( struct posix_file *file, int rc ) {
90
-	xfer_nullify ( &file->xfer );
91
-	xfer_close ( &file->xfer, rc );
91
+	intf_shutdown ( &file->xfer, rc );
92 92
 	file->rc = rc;
93 93
 }
94 94
 
95
-/**
96
- * Handle close() event
97
- *
98
- * @v xfer		POSIX file data transfer interface
99
- * @v rc		Reason for close
100
- */
101
-static void posix_file_xfer_close ( struct xfer_interface *xfer, int rc ) {
102
-	struct posix_file *file =
103
-		container_of ( xfer, struct posix_file, xfer );
104
-
105
-	posix_file_finished ( file, rc );
106
-}
107
-
108 95
 /**
109 96
  * Handle deliver_iob() event
110 97
  *
111
- * @v xfer		POSIX file data transfer interface
98
+ * @v file		POSIX file
112 99
  * @v iobuf		I/O buffer
113 100
  * @v meta		Data transfer metadata
114 101
  * @ret rc		Return status code
115 102
  */
116
-static int
117
-posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
118
-			      struct io_buffer *iobuf,
119
-			      struct xfer_metadata *meta ) {
120
-	struct posix_file *file =
121
-		container_of ( xfer, struct posix_file, xfer );
103
+static int posix_file_xfer_deliver ( struct posix_file *file,
104
+				     struct io_buffer *iobuf,
105
+				     struct xfer_metadata *meta ) {
122 106
 
123 107
 	/* Keep track of file position solely for the filesize */
124 108
 	if ( meta->whence != SEEK_CUR )
@@ -137,15 +121,15 @@ posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
137 121
 }
138 122
 
139 123
 /** POSIX file data transfer interface operations */
140
-static struct xfer_interface_operations posix_file_xfer_operations = {
141
-	.close		= posix_file_xfer_close,
142
-	.vredirect	= xfer_vreopen,
143
-	.window		= unlimited_xfer_window,
144
-	.alloc_iob	= default_xfer_alloc_iob,
145
-	.deliver_iob	= posix_file_xfer_deliver_iob,
146
-	.deliver_raw	= xfer_deliver_as_iob,
124
+static struct interface_operation posix_file_xfer_operations[] = {
125
+	INTF_OP ( xfer_deliver, struct posix_file *, posix_file_xfer_deliver ),
126
+	INTF_OP ( intf_close, struct posix_file *, posix_file_finished ),
147 127
 };
148 128
 
129
+/** POSIX file data transfer interface descriptor */
130
+static struct interface_descriptor posix_file_xfer_desc =
131
+	INTF_DESC ( struct posix_file, xfer, posix_file_xfer_operations );
132
+
149 133
 /**
150 134
  * Identify file by file descriptor
151 135
  *
@@ -201,8 +185,7 @@ int open ( const char *uri_string ) {
201 185
 	ref_init ( &file->refcnt, posix_file_free );
202 186
 	file->fd = fd;
203 187
 	file->rc = -EINPROGRESS;
204
-	xfer_init ( &file->xfer, &posix_file_xfer_operations,
205
-		    &file->refcnt );
188
+	intf_init ( &file->xfer, &posix_file_xfer_desc, &file->refcnt );
206 189
 	INIT_LIST_HEAD ( &file->data );
207 190
 
208 191
 	/* Open URI on data transfer interface */

+ 20
- 23
src/core/resolv.c Переглянути файл

@@ -299,7 +299,7 @@ struct named_socket {
299 299
 	/** Reference counter */
300 300
 	struct refcnt refcnt;
301 301
 	/** Data transfer interface */
302
-	struct xfer_interface xfer;
302
+	struct interface xfer;
303 303
 	/** Name resolution interface */
304 304
 	struct interface resolv;
305 305
 	/** Communication semantics (e.g. SOCK_STREAM) */
@@ -319,33 +319,30 @@ struct named_socket {
319 319
 static void named_close ( struct named_socket *named, int rc ) {
320 320
 	/* Shut down interfaces */
321 321
 	intf_shutdown ( &named->resolv, rc );
322
-	xfer_nullify ( &named->xfer );
323
-	xfer_close ( &named->xfer, rc );
322
+	intf_shutdown ( &named->xfer, rc );
324 323
 }
325 324
 
326 325
 /**
327
- * Handle close() event
326
+ * Check flow control window
328 327
  *
329
- * @v xfer		Data transfer interface
330
- * @v rc		Reason for close
328
+ * @v named		Named socket
329
+ * @ret len		Length of window
331 330
  */
332
-static void named_xfer_close ( struct xfer_interface *xfer, int rc ) {
333
-	struct named_socket *named =
334
-		container_of ( xfer, struct named_socket, xfer );
335
-
336
-	named_close ( named, rc );
331
+static size_t named_window ( struct named_socket *named __unused ) {
332
+	/* Not ready for data until we have redirected away */
333
+	return 0;
337 334
 }
338 335
 
339 336
 /** Named socket opener data transfer interface operations */
340
-static struct xfer_interface_operations named_xfer_ops = {
341
-	.close		= named_xfer_close,
342
-	.vredirect	= ignore_xfer_vredirect,
343
-	.window		= no_xfer_window,
344
-	.alloc_iob	= default_xfer_alloc_iob,
345
-	.deliver_iob	= xfer_deliver_as_raw,
346
-	.deliver_raw	= ignore_xfer_deliver_raw,
337
+static struct interface_operation named_xfer_ops[] = {
338
+	INTF_OP ( xfer_window, struct named_socket *, named_window ),
339
+	INTF_OP ( intf_close, struct named_socket *, named_close ),
347 340
 };
348 341
 
342
+/** Named socket opener data transfer interface descriptor */
343
+static struct interface_descriptor named_xfer_desc =
344
+	INTF_DESC ( struct named_socket, xfer, named_xfer_ops );
345
+
349 346
 /**
350 347
  * Name resolved
351 348
  *
@@ -357,7 +354,7 @@ static void named_resolv_done ( struct named_socket *named,
357 354
 	int rc;
358 355
 
359 356
 	/* Nullify data transfer interface */
360
-	xfer_nullify ( &named->xfer );
357
+	intf_nullify ( &named->xfer );
361 358
 
362 359
 	/* Redirect data-xfer interface */
363 360
 	if ( ( rc = xfer_redirect ( &named->xfer, LOCATION_SOCKET,
@@ -370,7 +367,7 @@ static void named_resolv_done ( struct named_socket *named,
370 367
 	} else {
371 368
 		/* Redirection succeeded - unplug data-xfer interface */
372 369
 		DBGC ( named, "NAMED %p redirected successfully\n", named );
373
-		xfer_unplug ( &named->xfer );
370
+		intf_unplug ( &named->xfer );
374 371
 	}
375 372
 
376 373
 	/* Terminate named socket opener */
@@ -396,7 +393,7 @@ static struct interface_descriptor named_resolv_desc =
396 393
  * @v local		Local socket address, or NULL
397 394
  * @ret rc		Return status code
398 395
  */
399
-int xfer_open_named_socket ( struct xfer_interface *xfer, int semantics,
396
+int xfer_open_named_socket ( struct interface *xfer, int semantics,
400 397
 			     struct sockaddr *peer, const char *name,
401 398
 			     struct sockaddr *local ) {
402 399
 	struct named_socket *named;
@@ -407,7 +404,7 @@ int xfer_open_named_socket ( struct xfer_interface *xfer, int semantics,
407 404
 	if ( ! named )
408 405
 		return -ENOMEM;
409 406
 	ref_init ( &named->refcnt, NULL );
410
-	xfer_init ( &named->xfer, &named_xfer_ops, &named->refcnt );
407
+	intf_init ( &named->xfer, &named_xfer_desc, &named->refcnt );
411 408
 	intf_init ( &named->resolv, &named_resolv_desc, &named->refcnt );
412 409
 	named->semantics = semantics;
413 410
 	if ( local ) {
@@ -423,7 +420,7 @@ int xfer_open_named_socket ( struct xfer_interface *xfer, int semantics,
423 420
 		goto err;
424 421
 
425 422
 	/* Attach parent interface, mortalise self, and return */
426
-	xfer_plug_plug ( &named->xfer, xfer );
423
+	intf_plug_plug ( &named->xfer, xfer );
427 424
 	ref_put ( &named->refcnt );
428 425
 	return 0;
429 426
 

+ 126
- 245
src/core/xfer.c Переглянути файл

@@ -21,7 +21,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
21 21
 #include <string.h>
22 22
 #include <stdio.h>
23 23
 #include <errno.h>
24
+#include <ipxe/iobuf.h>
24 25
 #include <ipxe/xfer.h>
26
+#include <ipxe/open.h>
25 27
 
26 28
 /** @file
27 29
  *
@@ -37,178 +39,206 @@ FILE_LICENCE ( GPL2_OR_LATER );
37 39
  */
38 40
 static struct xfer_metadata dummy_metadata;
39 41
 
40
-/**
41
- * Close data transfer interface
42
+/*****************************************************************************
43
+ *
44
+ * Data transfer interface operations
42 45
  *
43
- * @v xfer		Data transfer interface
44
- * @v rc		Reason for close
45 46
  */
46
-void xfer_close ( struct xfer_interface *xfer, int rc ) {
47
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
48
-	struct xfer_interface_operations *op = xfer->op;
49
-
50
-	DBGC ( xfer, "XFER %p->%p close\n", xfer, dest );
51
-
52
-	xfer_unplug ( xfer );
53
-	xfer_nullify ( xfer );
54
-	dest->op->close ( dest, rc );
55
-	xfer->op = op;
56
-	xfer_put ( dest );
57
-}
58 47
 
59 48
 /**
60 49
  * Send redirection event
61 50
  *
62
- * @v xfer		Data transfer interface
51
+ * @v intf		Data transfer interface
63 52
  * @v type		New location type
64 53
  * @v args		Remaining arguments depend upon location type
65 54
  * @ret rc		Return status code
66 55
  */
67
-int xfer_vredirect ( struct xfer_interface *xfer, int type, va_list args ) {
68
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
56
+int xfer_vredirect ( struct interface *intf, int type, va_list args ) {
57
+	struct interface *dest;
58
+	xfer_vredirect_TYPE ( void * ) *op =
59
+		intf_get_dest_op ( intf, xfer_vredirect, &dest );
60
+	void *object = intf_object ( dest );
69 61
 	int rc;
70 62
 
71
-	DBGC ( xfer, "XFER %p->%p redirect\n", xfer, dest );
63
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect\n",
64
+	       INTF_INTF_DBG ( intf, dest ) );
72 65
 
73
-	rc = dest->op->vredirect ( dest, type, args );
66
+	if ( op ) {
67
+		rc = op ( object, type, args );
68
+	} else {
69
+		/* Default is to reopen the interface as instructed */
70
+		rc = xfer_vreopen ( dest, type, args );
71
+	}
74 72
 
75 73
 	if ( rc != 0 ) {
76
-		DBGC ( xfer, "XFER %p<-%p redirect: %s\n", xfer, dest,
74
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect "
75
+		       "failed: %s\n", INTF_INTF_DBG ( intf, dest ),
77 76
 		       strerror ( rc ) );
78 77
 	}
79
-	xfer_put ( dest );
80
-	return rc;
81
-}
82 78
 
83
-/**
84
- * Send redirection event
85
- *
86
- * @v xfer		Data transfer interface
87
- * @v type		New location type
88
- * @v ...		Remaining arguments depend upon location type
89
- * @ret rc		Return status code
90
- */
91
-int xfer_redirect ( struct xfer_interface *xfer, int type, ... ) {
92
-	va_list args;
93
-	int rc;
94
-
95
-	va_start ( args, type );
96
-	rc = xfer_vredirect ( xfer, type, args );
97
-	va_end ( args );
79
+	intf_put ( dest );
98 80
 	return rc;
99 81
 }
100 82
 
101 83
 /**
102 84
  * Check flow control window
103 85
  *
104
- * @v xfer		Data transfer interface
86
+ * @v intf		Data transfer interface
105 87
  * @ret len		Length of window
106 88
  */
107
-size_t xfer_window ( struct xfer_interface *xfer ) {
108
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
89
+size_t xfer_window ( struct interface *intf ) {
90
+	struct interface *dest;
91
+	xfer_window_TYPE ( void * ) *op =
92
+		intf_get_dest_op ( intf, xfer_window, &dest );
93
+	void *object = intf_object ( dest );
109 94
 	size_t len;
110 95
 
111
-	len = dest->op->window ( dest );
96
+	if ( op ) {
97
+		len = op ( object );
98
+	} else {
99
+		/* Default is to provide an unlimited window */
100
+		len = ~( ( size_t ) 0 );
101
+	}
112 102
 
113
-	xfer_put ( dest );
103
+	intf_put ( dest );
114 104
 	return len;
115 105
 }
116 106
 
117 107
 /**
118 108
  * Allocate I/O buffer
119 109
  *
120
- * @v xfer		Data transfer interface
110
+ * @v intf		Data transfer interface
121 111
  * @v len		I/O buffer payload length
122 112
  * @ret iobuf		I/O buffer
123 113
  */
124
-struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer, size_t len ) {
125
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
114
+struct io_buffer * xfer_alloc_iob ( struct interface *intf, size_t len ) {
115
+	struct interface *dest;
116
+	xfer_alloc_iob_TYPE ( void * ) *op =
117
+		intf_get_dest_op ( intf, xfer_alloc_iob, &dest );
118
+	void *object = intf_object ( dest );
126 119
 	struct io_buffer *iobuf;
127 120
 
128
-	DBGC ( xfer, "XFER %p->%p alloc_iob %zd\n", xfer, dest, len );
121
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob %zd\n",
122
+	       INTF_INTF_DBG ( intf, dest ), len );
129 123
 
130
-	iobuf = dest->op->alloc_iob ( dest, len );
124
+	if ( op ) {
125
+		iobuf = op ( object, len );
126
+	} else {
127
+		/* Default is to allocate an I/O buffer with no
128
+		 * reserved space.
129
+		 */
130
+		iobuf = alloc_iob ( len );
131
+	}
131 132
 
132 133
 	if ( ! iobuf ) {
133
-		DBGC ( xfer, "XFER %p<-%p alloc_iob failed\n", xfer, dest );
134
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob "
135
+		       "failed\n", INTF_INTF_DBG ( intf, dest ) );
134 136
 	}
135
-	xfer_put ( dest );
137
+
138
+	intf_put ( dest );
136 139
 	return iobuf;
137 140
 }
138 141
 
139 142
 /**
140
- * Deliver datagram as I/O buffer with metadata
143
+ * Deliver datagram
141 144
  *
142
- * @v xfer		Data transfer interface
145
+ * @v intf		Data transfer interface
143 146
  * @v iobuf		Datagram I/O buffer
144 147
  * @v meta		Data transfer metadata
145 148
  * @ret rc		Return status code
146 149
  */
147
-int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
148
-			    struct io_buffer *iobuf,
149
-			    struct xfer_metadata *meta ) {
150
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
150
+int xfer_deliver ( struct interface *intf,
151
+		   struct io_buffer *iobuf,
152
+		   struct xfer_metadata *meta ) {
153
+	struct interface *dest;
154
+	xfer_deliver_TYPE ( void * ) *op =
155
+		intf_get_dest_op ( intf, xfer_deliver, &dest );
156
+	void *object = intf_object ( dest );
151 157
 	int rc;
152 158
 
153
-	DBGC ( xfer, "XFER %p->%p deliver_iob %zd\n", xfer, dest,
154
-	       iob_len ( iobuf ) );
159
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " deliver %zd\n",
160
+	       INTF_INTF_DBG ( intf, dest ), iob_len ( iobuf ) );
155 161
 
156
-	rc = dest->op->deliver_iob ( dest, iobuf, meta );
162
+	if ( op ) {
163
+		rc = op ( object, iobuf, meta );
164
+	} else {
165
+		/* Default is to discard the I/O buffer */
166
+		free_iob ( iobuf );
167
+		rc = -EPIPE;
168
+	}
157 169
 
158 170
 	if ( rc != 0 ) {
159
-		DBGC ( xfer, "XFER %p<-%p deliver_iob: %s\n", xfer, dest,
160
-		       strerror ( rc ) );
171
+		DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT
172
+		       " deliver failed: %s\n",
173
+		       INTF_INTF_DBG ( intf, dest ), strerror ( rc ) );
161 174
 	}
162
-	xfer_put ( dest );
175
+
176
+	intf_put ( dest );
177
+	return rc;
178
+}
179
+
180
+/*****************************************************************************
181
+ *
182
+ * Data transfer interface helper functions
183
+ *
184
+ */
185
+
186
+/**
187
+ * Send redirection event
188
+ *
189
+ * @v intf		Data transfer interface
190
+ * @v type		New location type
191
+ * @v ...		Remaining arguments depend upon location type
192
+ * @ret rc		Return status code
193
+ */
194
+int xfer_redirect ( struct interface *intf, int type, ... ) {
195
+	va_list args;
196
+	int rc;
197
+
198
+	va_start ( args, type );
199
+	rc = xfer_vredirect ( intf, type, args );
200
+	va_end ( args );
163 201
 	return rc;
164 202
 }
165 203
 
166 204
 /**
167
- * Deliver datagram as I/O buffer with metadata
205
+ * Deliver datagram as I/O buffer without metadata
168 206
  *
169
- * @v xfer		Data transfer interface
207
+ * @v intf		Data transfer interface
170 208
  * @v iobuf		Datagram I/O buffer
171 209
  * @ret rc		Return status code
172 210
  */
173
-int xfer_deliver_iob ( struct xfer_interface *xfer,
174
-		       struct io_buffer *iobuf ) {
175
-	return xfer_deliver_iob_meta ( xfer, iobuf, &dummy_metadata );
211
+int xfer_deliver_iob ( struct interface *intf, struct io_buffer *iobuf ) {
212
+	return xfer_deliver ( intf, iobuf, &dummy_metadata );
176 213
 }
177 214
 
178 215
 /**
179 216
  * Deliver datagram as raw data
180 217
  *
181
- * @v xfer		Data transfer interface
218
+ * @v intf		Data transfer interface
182 219
  * @v iobuf		Datagram I/O buffer
183 220
  * @ret rc		Return status code
184 221
  */
185
-int xfer_deliver_raw ( struct xfer_interface *xfer,
186
-		       const void *data, size_t len ) {
187
-	struct xfer_interface *dest = xfer_get_dest ( xfer );
188
-	int rc;
189
-
190
-	DBGC ( xfer, "XFER %p->%p deliver_raw %p+%zd\n", xfer, dest,
191
-	       data, len );
222
+int xfer_deliver_raw ( struct interface *intf, const void *data, size_t len ) {
223
+	struct io_buffer *iobuf;
192 224
 
193
-	rc = dest->op->deliver_raw ( dest, data, len );
225
+	iobuf = xfer_alloc_iob ( intf, len );
226
+	if ( ! iobuf )
227
+		return -ENOMEM;
194 228
 
195
-	if ( rc != 0 ) {
196
-		DBGC ( xfer, "XFER %p<-%p deliver_raw: %s\n", xfer, dest,
197
-		       strerror ( rc ) );
198
-	}
199
-	xfer_put ( dest );
200
-	return rc;
229
+	memcpy ( iob_put ( iobuf, len ), data, len );
230
+	return xfer_deliver_iob ( intf, iobuf );
201 231
 }
202 232
 
203 233
 /**
204 234
  * Deliver formatted string
205 235
  *
206
- * @v xfer		Data transfer interface
236
+ * @v intf		Data transfer interface
207 237
  * @v format		Format string
208 238
  * @v args		Arguments corresponding to the format string
209 239
  * @ret rc		Return status code
210 240
  */
211
-int xfer_vprintf ( struct xfer_interface *xfer, const char *format,
241
+int xfer_vprintf ( struct interface *intf, const char *format,
212 242
 		   va_list args ) {
213 243
 	size_t len;
214 244
 	va_list args_tmp;
@@ -219,24 +249,24 @@ int xfer_vprintf ( struct xfer_interface *xfer, const char *format,
219 249
 		char buf[len + 1];
220 250
 		vsnprintf ( buf, sizeof ( buf ), format, args_tmp );
221 251
 		va_end ( args_tmp );
222
-		return xfer_deliver_raw ( xfer, buf, len );
252
+		return xfer_deliver_raw ( intf, buf, len );
223 253
 	}
224 254
 }
225 255
 
226 256
 /**
227 257
  * Deliver formatted string
228 258
  *
229
- * @v xfer		Data transfer interface
259
+ * @v intf		Data transfer interface
230 260
  * @v format		Format string
231 261
  * @v ...		Arguments corresponding to the format string
232 262
  * @ret rc		Return status code
233 263
  */
234
-int xfer_printf ( struct xfer_interface *xfer, const char *format, ... ) {
264
+int xfer_printf ( struct interface *intf, const char *format, ... ) {
235 265
 	va_list args;
236 266
 	int rc;
237 267
 
238 268
 	va_start ( args, format );
239
-	rc = xfer_vprintf ( xfer, format, args );
269
+	rc = xfer_vprintf ( intf, format, args );
240 270
 	va_end ( args );
241 271
 	return rc;
242 272
 }
@@ -244,174 +274,25 @@ int xfer_printf ( struct xfer_interface *xfer, const char *format, ... ) {
244 274
 /**
245 275
  * Seek to position
246 276
  *
247
- * @v xfer		Data transfer interface
277
+ * @v intf		Data transfer interface
248 278
  * @v offset		Offset to new position
249 279
  * @v whence		Basis for new position
250 280
  * @ret rc		Return status code
251 281
  */
252
-int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence ) {
282
+int xfer_seek ( struct interface *intf, off_t offset, int whence ) {
253 283
 	struct io_buffer *iobuf;
254 284
 	struct xfer_metadata meta = {
255 285
 		.offset = offset,
256 286
 		.whence = whence,
257 287
 	};
258 288
 
259
-	DBGC ( xfer, "XFER %p seek %s+%ld\n", xfer,
260
-	       whence_text ( whence ), offset );
289
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " seek %s+%ld\n",
290
+	       INTF_DBG ( intf ), whence_text ( whence ), offset );
261 291
 
262 292
 	/* Allocate and send a zero-length data buffer */
263
-	iobuf = xfer_alloc_iob ( xfer, 0 );
293
+	iobuf = xfer_alloc_iob ( intf, 0 );
264 294
 	if ( ! iobuf )
265 295
 		return -ENOMEM;
266
-	return xfer_deliver_iob_meta ( xfer, iobuf, &meta );
267
-}
268
-
269
-/****************************************************************************
270
- *
271
- * Helper methods
272
- *
273
- * These functions are designed to be used as methods in the
274
- * xfer_interface_operations table.
275
- *
276
- */
277 296
 
278
-/**
279
- * Ignore close() event
280
- *
281
- * @v xfer		Data transfer interface
282
- * @v rc		Reason for close
283
- */
284
-void ignore_xfer_close ( struct xfer_interface *xfer __unused,
285
-			 int rc __unused ) {
286
-	/* Nothing to do */
297
+	return xfer_deliver ( intf, iobuf, &meta );
287 298
 }
288
-
289
-/**
290
- * Ignore vredirect() event
291
- *
292
- * @v xfer		Data transfer interface
293
- * @v type		New location type
294
- * @v args		Remaining arguments depend upon location type
295
- * @ret rc		Return status code
296
- */
297
-int ignore_xfer_vredirect ( struct xfer_interface *xfer __unused,
298
-			    int type __unused, va_list args __unused ) {
299
-	return 0;
300
-}
301
-
302
-/**
303
- * Unlimited flow control window
304
- *
305
- * @v xfer		Data transfer interface
306
- * @ret len		Length of window
307
- *
308
- * This handler indicates that the interface is always ready to accept
309
- * data.
310
- */
311
-size_t unlimited_xfer_window ( struct xfer_interface *xfer __unused ) {
312
-	return ~( ( size_t ) 0 );
313
-}
314
-
315
-/**
316
- * No flow control window
317
- *
318
- * @v xfer		Data transfer interface
319
- * @ret len		Length of window
320
- *
321
- * This handler indicates that the interface is never ready to accept
322
- * data.
323
- */
324
-size_t no_xfer_window ( struct xfer_interface *xfer __unused ) {
325
-	return 0;
326
-}
327
-
328
-/**
329
- * Allocate I/O buffer
330
- *
331
- * @v xfer		Data transfer interface
332
- * @v len		I/O buffer payload length
333
- * @ret iobuf		I/O buffer
334
- */
335
-struct io_buffer *
336
-default_xfer_alloc_iob ( struct xfer_interface *xfer __unused, size_t len ) {
337
-	return alloc_iob ( len );
338
-}
339
-
340
-/**
341
- * Deliver datagram as raw data
342
- *
343
- * @v xfer		Data transfer interface
344
- * @v iobuf		Datagram I/O buffer
345
- * @v meta		Data transfer metadata
346
- * @ret rc		Return status code
347
- *
348
- * This function is intended to be used as the deliver() method for
349
- * data transfer interfaces that prefer to handle raw data.
350
- */
351
-int xfer_deliver_as_raw ( struct xfer_interface *xfer,
352
-			  struct io_buffer *iobuf,
353
-			  struct xfer_metadata *meta __unused ) {
354
-	int rc;
355
-
356
-	rc = xfer->op->deliver_raw ( xfer, iobuf->data, iob_len ( iobuf ) );
357
-	free_iob ( iobuf );
358
-	return rc;
359
-}
360
-
361
-/**
362
- * Deliver datagram as I/O buffer
363
- *
364
- * @v xfer		Data transfer interface
365
- * @v data		Data buffer
366
- * @v len		Length of data buffer
367
- * @ret rc		Return status code
368
- *
369
- * This function is intended to be used as the deliver_raw() method
370
- * for data transfer interfaces that prefer to handle I/O buffers.
371
- */
372
-int xfer_deliver_as_iob ( struct xfer_interface *xfer,
373
-			  const void *data, size_t len ) {
374
-	struct io_buffer *iobuf;
375
-
376
-	iobuf = xfer->op->alloc_iob ( xfer, len );
377
-	if ( ! iobuf )
378
-		return -ENOMEM;
379
-
380
-	memcpy ( iob_put ( iobuf, len ), data, len );
381
-	return xfer->op->deliver_iob ( xfer, iobuf, &dummy_metadata );
382
-}
383
-
384
-/**
385
- * Ignore datagram as raw data event
386
- *
387
- * @v xfer		Data transfer interface
388
- * @v data		Data buffer
389
- * @v len		Length of data buffer
390
- * @ret rc		Return status code
391
- */
392
-int ignore_xfer_deliver_raw ( struct xfer_interface *xfer,
393
-			      const void *data __unused, size_t len ) {
394
-	DBGC ( xfer, "XFER %p %zd bytes delivered %s\n", xfer, len,
395
-	       ( ( xfer == &null_xfer ) ?
396
-		 "before connection" : "after termination" ) );
397
-	return 0;
398
-}
399
-
400
-/** Null data transfer interface operations */
401
-struct xfer_interface_operations null_xfer_ops = {
402
-	.close		= ignore_xfer_close,
403
-	.vredirect	= ignore_xfer_vredirect,
404
-	.window		= unlimited_xfer_window,
405
-	.alloc_iob	= default_xfer_alloc_iob,
406
-	.deliver_iob	= xfer_deliver_as_raw,
407
-	.deliver_raw	= ignore_xfer_deliver_raw,
408
-};
409
-
410
-/**
411
- * Null data transfer interface
412
- *
413
- * This is the interface to which data transfer interfaces are
414
- * connected when unplugged.  It will never generate messages, and
415
- * will silently absorb all received messages.
416
- */
417
-struct xfer_interface null_xfer = XFER_INIT ( &null_xfer_ops );

+ 14
- 32
src/drivers/block/srp.c Переглянути файл

@@ -75,7 +75,7 @@ static void srp_scsi_done ( struct srp_device *srp, int rc ) {
75 75
 static void srp_fail ( struct srp_device *srp, int rc ) {
76 76
 
77 77
 	/* Close underlying socket */
78
-	xfer_close ( &srp->socket, rc );
78
+	intf_restart ( &srp->socket, rc );
79 79
 
80 80
 	/* Clear session state */
81 81
 	srp->state = 0;
@@ -364,16 +364,14 @@ static int srp_unrecognised ( struct srp_device *srp,
364 364
 /**
365 365
  * Receive data from underlying socket
366 366
  *
367
- * @v xfer		Data transfer interface
367
+ * @v srp		SRP device
368 368
  * @v iobuf		Datagram I/O buffer
369 369
  * @v meta		Data transfer metadata
370 370
  * @ret rc		Return status code
371 371
  */
372
-static int srp_xfer_deliver_iob ( struct xfer_interface *xfer,
373
-				  struct io_buffer *iobuf,
374
-				  struct xfer_metadata *meta __unused ) {
375
-	struct srp_device *srp =
376
-		container_of ( xfer, struct srp_device, socket );
372
+static int srp_xfer_deliver ( struct srp_device *srp,
373
+			      struct io_buffer *iobuf,
374
+			      struct xfer_metadata *meta __unused ) {
377 375
 	struct srp_common *common = iobuf->data;
378 376
 	int ( * type ) ( struct srp_device *srp, struct io_buffer *iobuf );
379 377
 	int rc;
@@ -405,31 +403,16 @@ static int srp_xfer_deliver_iob ( struct xfer_interface *xfer,
405 403
 	return rc;
406 404
 }
407 405
 
408
-/**
409
- * Underlying socket closed
410
- *
411
- * @v xfer		Data transfer interface
412
- * @v rc		Reason for close
413
- */
414
-static void srp_xfer_close ( struct xfer_interface *xfer, int rc ) {
415
-	struct srp_device *srp =
416
-		container_of ( xfer, struct srp_device, socket );
417
-
418
-	DBGC ( srp, "SRP %p socket closed: %s\n", srp, strerror ( rc ) );
419
-
420
-	srp_fail ( srp, rc );
421
-}
422
-
423 406
 /** SRP data transfer interface operations */
424
-static struct xfer_interface_operations srp_xfer_operations = {
425
-	.close		= srp_xfer_close,
426
-	.vredirect	= ignore_xfer_vredirect,
427
-	.window		= unlimited_xfer_window,
428
-	.alloc_iob	= default_xfer_alloc_iob,
429
-	.deliver_iob	= srp_xfer_deliver_iob,
430
-	.deliver_raw	= xfer_deliver_as_iob,
407
+static struct interface_operation srp_xfer_operations[] = {
408
+	INTF_OP ( xfer_deliver, struct srp_device *, srp_xfer_deliver ),
409
+	INTF_OP ( intf_close, struct srp_device *, srp_fail ),
431 410
 };
432 411
 
412
+/** SRP data transfer interface descriptor */
413
+static struct interface_descriptor srp_xfer_desc =
414
+	INTF_DESC ( struct srp_device, socket, srp_xfer_operations );
415
+
433 416
 /**
434 417
  * Issue SCSI command via SRP
435 418
  *
@@ -483,7 +466,7 @@ int srp_attach ( struct scsi_device *scsi, const char *root_path ) {
483 466
 		goto err_alloc;
484 467
 	}
485 468
 	ref_init ( &srp->refcnt, NULL );
486
-	xfer_init ( &srp->socket, &srp_xfer_operations, &srp->refcnt );
469
+	intf_init ( &srp->socket, &srp_xfer_desc, &srp->refcnt );
487 470
 	srp->transport = transport;
488 471
 	DBGC ( srp, "SRP %p using %s\n", srp, root_path );
489 472
 
@@ -516,8 +499,7 @@ void srp_detach ( struct scsi_device *scsi ) {
516 499
 		container_of ( scsi->backend, struct srp_device, refcnt );
517 500
 
518 501
 	/* Close socket */
519
-	xfer_nullify ( &srp->socket );
520
-	xfer_close ( &srp->socket, 0 );
502
+	intf_shutdown ( &srp->socket, 0 );
521 503
 	scsi->command = scsi_detached_command;
522 504
 	ref_put ( scsi->backend );
523 505
 	scsi->backend = NULL;

+ 0
- 75
src/include/ipxe/filter.h Переглянути файл

@@ -1,75 +0,0 @@
1
-#ifndef _IPXE_FILTER_H
2
-#define _IPXE_FILTER_H
3
-
4
-/** @file
5
- *
6
- * Data transfer filters
7
- *
8
- */
9
-
10
-FILE_LICENCE ( GPL2_OR_LATER );
11
-
12
-#include <stddef.h>
13
-#include <ipxe/xfer.h>
14
-
15
-/**
16
- * Half of a data transfer filter
17
- *
18
- * Embed two of these structures within a structure implementing a
19
- * data transfer filter, and intialise with filter_init().  You can
20
- * then use the filter_xxx() methods as the data transfer interface
21
- * methods as required.
22
- */
23
-struct xfer_filter_half {
24
-	/** Data transfer interface */
25
-	struct xfer_interface xfer;
26
-	/** Other half of the data transfer filter */
27
-	struct xfer_filter_half *other;
28
-};
29
-
30
-/**
31
- * Get data transfer interface for the other half of a data transfer filter
32
- *
33
- * @v xfer		Data transfer interface
34
- * @ret other		Other half's data transfer interface
35
- */
36
-static inline __attribute__ (( always_inline )) struct xfer_interface *
37
-filter_other_half ( struct xfer_interface *xfer ) {
38
-	struct xfer_filter_half *half = 
39
-		container_of ( xfer, struct xfer_filter_half, xfer );
40
-	return &half->other->xfer;
41
-}
42
-
43
-extern void filter_close ( struct xfer_interface *xfer, int rc );
44
-extern int filter_vredirect ( struct xfer_interface *xfer, int type,
45
-			      va_list args );
46
-extern size_t filter_window ( struct xfer_interface *xfer );
47
-extern struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
48
-					     size_t len );
49
-extern int filter_deliver_iob ( struct xfer_interface *xfer,
50
-				struct io_buffer *iobuf,
51
-				struct xfer_metadata *meta );
52
-extern int filter_deliver_raw ( struct xfer_interface *xfer, const void *data,
53
-				size_t len );
54
-
55
-/**
56
- * Initialise a data transfer filter
57
- *
58
- * @v left		"Left" half of the filter
59
- * @v left_op		Data transfer interface operations for "left" half
60
- * @v right		"Right" half of the filter
61
- * @v right_op		Data transfer interface operations for "right" half
62
- * @v refcnt		Containing object reference counter, or NULL
63
- */
64
-static inline void filter_init ( struct xfer_filter_half *left,
65
-				 struct xfer_interface_operations *left_op,
66
-				 struct xfer_filter_half *right,
67
-				 struct xfer_interface_operations *right_op,
68
-				 struct refcnt *refcnt ) {
69
-	xfer_init ( &left->xfer, left_op, refcnt );
70
-	xfer_init ( &right->xfer, right_op, refcnt );
71
-	left->other = right;
72
-	right->other = left;
73
-}
74
-
75
-#endif /* _IPXE_FILTER_H */

+ 3
- 3
src/include/ipxe/http.h Переглянути файл

@@ -15,9 +15,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
15 15
 /** HTTPS default port */
16 16
 #define HTTPS_PORT 443
17 17
 
18
-extern int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
18
+extern int http_open_filter ( struct interface *xfer, struct uri *uri,
19 19
 			      unsigned int default_port,
20
-			      int ( * filter ) ( struct xfer_interface *,
21
-						 struct xfer_interface ** ) );
20
+			      int ( * filter ) ( struct interface *,
21
+						 struct interface ** ) );
22 22
 
23 23
 #endif /* _IPXE_HTTP_H */

+ 1
- 1
src/include/ipxe/ib_cmrc.h Переглянути файл

@@ -12,7 +12,7 @@ FILE_LICENCE ( BSD2 );
12 12
 #include <ipxe/infiniband.h>
13 13
 #include <ipxe/xfer.h>
14 14
 
15
-extern int ib_cmrc_open ( struct xfer_interface *xfer,
15
+extern int ib_cmrc_open ( struct interface *xfer,
16 16
 			  struct ib_device *ibdev,
17 17
 			  struct ib_gid *dgid,
18 18
 			  struct ib_gid_half *service_id );

+ 1
- 1
src/include/ipxe/iscsi.h Переглянути файл

@@ -498,7 +498,7 @@ struct iscsi_session {
498 498
 	struct refcnt refcnt;
499 499
 
500 500
 	/** Transport-layer socket */
501
-	struct xfer_interface socket;
501
+	struct interface socket;
502 502
 
503 503
 	/** Target address */
504 504
 	char *target_address;

+ 14
- 14
src/include/ipxe/open.h Переглянути файл

@@ -13,8 +13,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
13 13
 #include <ipxe/tables.h>
14 14
 #include <ipxe/socket.h>
15 15
 
16
-struct xfer_interface;
17 16
 struct uri;
17
+struct interface;
18 18
 
19 19
 /** Location types */
20 20
 enum {
@@ -53,11 +53,11 @@ struct uri_opener {
53 53
 	const char *scheme;
54 54
 	/** Open URI
55 55
 	 *
56
-	 * @v xfer		Data transfer interface
56
+	 * @v intf		Object interface
57 57
 	 * @v uri		URI
58 58
 	 * @ret rc		Return status code
59 59
 	 */
60
-	int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
60
+	int ( * open ) ( struct interface *intf, struct uri *uri );
61 61
 };
62 62
 
63 63
 /** URI opener table */
@@ -74,12 +74,12 @@ struct socket_opener {
74 74
 	int family;
75 75
 	/** Open socket
76 76
 	 *
77
-	 * @v xfer		Data transfer interface
77
+	 * @v intf		Object interface
78 78
 	 * @v peer		Peer socket address
79 79
 	 * @v local		Local socket address, or NULL
80 80
 	 * @ret rc		Return status code
81 81
 	 */
82
-	int ( * open ) ( struct xfer_interface *xfer, struct sockaddr *peer,
82
+	int ( * open ) ( struct interface *intf, struct sockaddr *peer,
83 83
 			 struct sockaddr *local );
84 84
 };
85 85
 
@@ -89,17 +89,17 @@ struct socket_opener {
89 89
 /** Register a socket opener */
90 90
 #define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
91 91
 
92
-extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri );
93
-extern int xfer_open_uri_string ( struct xfer_interface *xfer,
92
+extern int xfer_open_uri ( struct interface *intf, struct uri *uri );
93
+extern int xfer_open_uri_string ( struct interface *intf,
94 94
 				  const char *uri_string );
95
-extern int xfer_open_named_socket ( struct xfer_interface *xfer,
96
-				    int semantics, struct sockaddr *peer,
97
-				    const char *name, struct sockaddr *local );
98
-extern int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
95
+extern int xfer_open_named_socket ( struct interface *intf, int semantics,
96
+				    struct sockaddr *peer, const char *name,
97
+				    struct sockaddr *local );
98
+extern int xfer_open_socket ( struct interface *intf, int semantics,
99 99
 			      struct sockaddr *peer, struct sockaddr *local );
100
-extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
101
-extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
102
-extern int xfer_vreopen ( struct xfer_interface *xfer, int type,
100
+extern int xfer_vopen ( struct interface *intf, int type, va_list args );
101
+extern int xfer_open ( struct interface *intf, int type, ... );
102
+extern int xfer_vreopen ( struct interface *intf, int type,
103 103
 			  va_list args );
104 104
 
105 105
 #endif /* _IPXE_OPEN_H */

+ 1
- 1
src/include/ipxe/srp.h Переглянути файл

@@ -832,7 +832,7 @@ struct srp_device {
832 832
 	struct scsi_command *command;
833 833
 
834 834
 	/** Underlying data transfer interface */
835
-	struct xfer_interface socket;
835
+	struct interface socket;
836 836
 
837 837
 	/** Transport type */
838 838
 	struct srp_transport_type *transport;

+ 5
- 5
src/include/ipxe/tls.h Переглянути файл

@@ -11,7 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12 12
 #include <stdint.h>
13 13
 #include <ipxe/refcnt.h>
14
-#include <ipxe/filter.h>
14
+#include <ipxe/interface.h>
15 15
 #include <ipxe/process.h>
16 16
 #include <ipxe/crypto.h>
17 17
 #include <ipxe/md5.h>
@@ -134,9 +134,9 @@ struct tls_session {
134 134
 	struct refcnt refcnt;
135 135
 
136 136
 	/** Plaintext stream */
137
-	struct xfer_filter_half plainstream;
137
+	struct interface plainstream;
138 138
 	/** Ciphertext stream */
139
-	struct xfer_filter_half cipherstream;
139
+	struct interface cipherstream;
140 140
 
141 141
 	/** Current TX cipher specification */
142 142
 	struct tls_cipherspec tx_cipherspec;
@@ -181,7 +181,7 @@ struct tls_session {
181 181
 	void *rx_data;
182 182
 };
183 183
 
184
-extern int add_tls ( struct xfer_interface *xfer,
185
-		     struct xfer_interface **next );
184
+extern int add_tls ( struct interface *xfer,
185
+		     struct interface **next );
186 186
 
187 187
 #endif /* _IPXE_TLS_H */

+ 4
- 3
src/include/ipxe/udp.h Переглянути файл

@@ -16,7 +16,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
16 16
 #include <ipxe/tcpip.h>
17 17
 #include <ipxe/if_ether.h>
18 18
 
19
-struct xfer_interface;
19
+struct interface;
20
+struct sockaddr;
20 21
 
21 22
 /**
22 23
  * UDP constants
@@ -40,8 +41,8 @@ struct udp_header {
40 41
 	uint16_t chksum;
41 42
 };
42 43
 
43
-extern int udp_open_promisc ( struct xfer_interface *xfer );
44
-extern int udp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
44
+extern int udp_open_promisc ( struct interface *xfer );
45
+extern int udp_open ( struct interface *xfer, struct sockaddr *peer,
45 46
 		      struct sockaddr *local );
46 47
 
47 48
 #endif /* _IPXE_UDP_H */

+ 31
- 214
src/include/ipxe/xfer.h Переглянути файл

@@ -12,88 +12,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
12 12
 #include <stddef.h>
13 13
 #include <stdarg.h>
14 14
 #include <ipxe/interface.h>
15
-#include <ipxe/iobuf.h>
16 15
 
17
-struct xfer_interface;
18 16
 struct xfer_metadata;
19
-
20
-/** Data transfer interface operations */
21
-struct xfer_interface_operations {
22
-	/** Close interface
23
-	 *
24
-	 * @v xfer		Data transfer interface
25
-	 * @v rc		Reason for close
26
-	 */
27
-	void ( * close ) ( struct xfer_interface *xfer, int rc );
28
-	/** Redirect to new location
29
-	 *
30
-	 * @v xfer		Data transfer interface
31
-	 * @v type		New location type
32
-	 * @v args		Remaining arguments depend upon location type
33
-	 * @ret rc		Return status code
34
-	 */
35
-	int ( * vredirect ) ( struct xfer_interface *xfer, int type,
36
-			      va_list args );
37
-	/** Check flow control window
38
-	 *
39
-	 * @v xfer		Data transfer interface
40
-	 * @ret len		Length of window
41
-	 *
42
-	 * Flow control is regarded as advisory but not mandatory.
43
-	 * Users who have control over their own rate of data
44
-	 * generation should perform a flow control check before
45
-	 * generating new data.  Users who have no control (such as
46
-	 * NIC drivers or filter layers) are not obliged to check.
47
-	 *
48
-	 * Data transfer interfaces must be prepared to accept
49
-	 * datagrams even if they are advertising a window of zero
50
-	 * bytes.
51
-	 */
52
-	size_t ( * window ) ( struct xfer_interface *xfer );
53
-	/** Allocate I/O buffer
54
-	 *
55
-	 * @v xfer		Data transfer interface
56
-	 * @v len		I/O buffer payload length
57
-	 * @ret iobuf		I/O buffer
58
-	 */
59
-	struct io_buffer * ( * alloc_iob ) ( struct xfer_interface *xfer,
60
-					     size_t len );
61
-	/** Deliver datagram as I/O buffer with metadata
62
-	 *
63
-	 * @v xfer		Data transfer interface
64
-	 * @v iobuf		Datagram I/O buffer
65
-	 * @v meta		Data transfer metadata
66
-	 * @ret rc		Return status code
67
-	 *
68
-	 * A data transfer interface that wishes to support only raw
69
-	 * data delivery should set this method to
70
-	 * xfer_deliver_as_raw().
71
-	 */
72
-	int ( * deliver_iob ) ( struct xfer_interface *xfer,
73
-				struct io_buffer *iobuf,
74
-				struct xfer_metadata *meta );
75
-	/** Deliver datagram as raw data
76
-	 *
77
-	 * @v xfer		Data transfer interface
78
-	 * @v data		Data buffer
79
-	 * @v len		Length of data buffer
80
-	 * @ret rc		Return status code
81
-	 *
82
-	 * A data transfer interface that wishes to support only I/O
83
-	 * buffer delivery should set this method to
84
-	 * xfer_deliver_as_iob().
85
-	 */
86
-	int ( * deliver_raw ) ( struct xfer_interface *xfer,
87
-				const void *data, size_t len );
88
-};
89
-
90
-/** A data transfer interface */
91
-struct xfer_interface {
92
-	/** Generic object communication interface */
93
-	struct interface intf;
94
-	/** Operations for received messages */
95
-	struct xfer_interface_operations *op;
96
-};
17
+struct io_buffer;
18
+struct sockaddr;
19
+struct net_device;
97 20
 
98 21
 /** Basis positions for seek() events */
99 22
 enum seek_whence {
@@ -132,146 +55,40 @@ whence_text ( int whence ) {
132 55
 	}
133 56
 }
134 57
 
135
-extern struct xfer_interface null_xfer;
136
-extern struct xfer_interface_operations null_xfer_ops;
58
+/* Data transfer interface operations */
137 59
 
138
-extern void xfer_close ( struct xfer_interface *xfer, int rc );
139
-extern int xfer_vredirect ( struct xfer_interface *xfer, int type,
60
+extern int xfer_vredirect ( struct interface *intf, int type,
140 61
 			    va_list args );
141
-extern int xfer_redirect ( struct xfer_interface *xfer, int type, ... );
142
-extern size_t xfer_window ( struct xfer_interface *xfer );
143
-extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer,
144
-					   size_t len );
145
-extern int xfer_deliver_iob ( struct xfer_interface *xfer,
146
-			      struct io_buffer *iobuf );
147
-extern int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
148
-				   struct io_buffer *iobuf,
149
-				   struct xfer_metadata *meta );
150
-extern int xfer_deliver_raw ( struct xfer_interface *xfer,
151
-			      const void *data, size_t len );
152
-extern int xfer_vprintf ( struct xfer_interface *xfer,
153
-			  const char *format, va_list args );
154
-extern int __attribute__ (( format ( printf, 2, 3 ) ))
155
-xfer_printf ( struct xfer_interface *xfer, const char *format, ... );
156
-extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence );
157
-
158
-extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
159
-extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,
160
-				   int type, va_list args );
161
-extern size_t unlimited_xfer_window ( struct xfer_interface *xfer );
162
-extern size_t no_xfer_window ( struct xfer_interface *xfer );
163
-extern struct io_buffer * default_xfer_alloc_iob ( struct xfer_interface *xfer,
164
-						   size_t len );
165
-extern int xfer_deliver_as_raw ( struct xfer_interface *xfer,
166
-				 struct io_buffer *iobuf,
167
-				 struct xfer_metadata *meta );
168
-extern int xfer_deliver_as_iob ( struct xfer_interface *xfer,
169
-				 const void *data, size_t len );
170
-extern int ignore_xfer_deliver_raw ( struct xfer_interface *xfer,
171
-				     const void *data __unused, size_t len );
172
-
173
-/**
174
- * Initialise a data transfer interface
175
- *
176
- * @v xfer		Data transfer interface
177
- * @v op		Data transfer interface operations
178
- * @v refcnt		Containing object reference counter, or NULL
179
- */
180
-static inline void xfer_init ( struct xfer_interface *xfer,
181
-			       struct xfer_interface_operations *op,
182
-			       struct refcnt *refcnt ) {
183
-	xfer->intf.dest = &null_xfer.intf;
184
-	xfer->intf.refcnt = refcnt;
185
-	xfer->op = op;
186
-}
187
-
188
-/**
189
- * Initialise a static data transfer interface
190
- *
191
- * @v operations		Data transfer interface operations
192
- */
193
-#define XFER_INIT( operations ) {			\
194
-		.intf = {				\
195
-			.dest = &null_xfer.intf,	\
196
-			.refcnt = NULL,			\
197
-		},					\
198
-		.op = operations,			\
199
-	}
62
+#define xfer_vredirect_TYPE( object_type ) \
63
+	typeof ( int ( object_type, int type, va_list args ) )
200 64
 
201
-/**
202
- * Get data transfer interface from generic object communication interface
203
- *
204
- * @v intf		Generic object communication interface
205
- * @ret xfer		Data transfer interface
206
- */
207
-static inline __attribute__ (( always_inline )) struct xfer_interface *
208
-intf_to_xfer ( struct interface *intf ) {
209
-	return container_of ( intf, struct xfer_interface, intf );
210
-}
211
-
212
-/**
213
- * Get reference to destination data transfer interface
214
- *
215
- * @v xfer		Data transfer interface
216
- * @ret dest		Destination interface
217
- */
218
-static inline __attribute__ (( always_inline )) struct xfer_interface *
219
-xfer_get_dest ( struct xfer_interface *xfer ) {
220
-	return intf_to_xfer ( intf_get ( xfer->intf.dest ) );
221
-}
65
+extern size_t xfer_window ( struct interface *intf );
66
+#define xfer_window_TYPE( object_type ) \
67
+	typeof ( size_t ( object_type ) )
222 68
 
223
-/**
224
- * Drop reference to data transfer interface
225
- *
226
- * @v xfer		Data transfer interface
227
- */
228
-static inline __attribute__ (( always_inline )) void
229
-xfer_put ( struct xfer_interface *xfer ) {
230
-	intf_put ( &xfer->intf );
231
-}
232
-
233
-/**
234
- * Plug a data transfer interface into a new destination interface
235
- *
236
- * @v xfer		Data transfer interface
237
- * @v dest		New destination interface
238
- */
239
-static inline __attribute__ (( always_inline )) void
240
-xfer_plug ( struct xfer_interface *xfer, struct xfer_interface *dest ) {
241
-	intf_plug ( &xfer->intf, &dest->intf );
242
-}
69
+extern struct io_buffer * xfer_alloc_iob ( struct interface *intf,
70
+					   size_t len );
71
+#define xfer_alloc_iob_TYPE( object_type ) \
72
+	typeof ( struct io_buffer * ( object_type, size_t len ) )
243 73
 
244
-/**
245
- * Plug two data transfer interfaces together
246
- *
247
- * @v a			Data transfer interface A
248
- * @v b			Data transfer interface B
249
- */
250
-static inline __attribute__ (( always_inline )) void
251
-xfer_plug_plug ( struct xfer_interface *a, struct xfer_interface *b ) {
252
-	intf_plug_plug ( &a->intf, &b->intf );
253
-}
74
+extern int xfer_deliver ( struct interface *intf,
75
+			  struct io_buffer *iobuf,
76
+			  struct xfer_metadata *meta );
77
+#define xfer_deliver_TYPE( object_type )			\
78
+	typeof ( int ( object_type, struct io_buffer *iobuf,	\
79
+		       struct xfer_metadata *meta ) )
254 80
 
255
-/**
256
- * Unplug a data transfer interface
257
- *
258
- * @v xfer		Data transfer interface
259
- */
260
-static inline __attribute__ (( always_inline )) void
261
-xfer_unplug ( struct xfer_interface *xfer ) {
262
-	intf_plug ( &xfer->intf, &null_xfer.intf );
263
-}
81
+/* Data transfer interface helper functions */
264 82
 
265
-/**
266
- * Stop using a data transfer interface
267
- *
268
- * @v xfer		Data transfer interface
269
- *
270
- * After calling this method, no further messages will be received via
271
- * the interface.
272
- */
273
-static inline void xfer_nullify ( struct xfer_interface *xfer ) {
274
-	xfer->op = &null_xfer_ops;
275
-};
83
+extern int xfer_redirect ( struct interface *xfer, int type, ... );
84
+extern int xfer_deliver_iob ( struct interface *intf,
85
+			      struct io_buffer *iobuf );
86
+extern int xfer_deliver_raw ( struct interface *intf,
87
+			      const void *data, size_t len );
88
+extern int xfer_vprintf ( struct interface *intf,
89
+			  const char *format, va_list args );
90
+extern int __attribute__ (( format ( printf, 2, 3 ) ))
91
+xfer_printf ( struct interface *intf, const char *format, ... );
92
+extern int xfer_seek ( struct interface *intf, off_t offset, int whence );
276 93
 
277 94
 #endif /* _IPXE_XFER_H */

+ 21
- 37
src/net/infiniband/ib_cmrc.c Переглянути файл

@@ -70,7 +70,7 @@ struct ib_cmrc_connection {
70 70
 	/** Reference count */
71 71
 	struct refcnt refcnt;
72 72
 	/** Data transfer interface */
73
-	struct xfer_interface xfer;
73
+	struct interface xfer;
74 74
 	/** Infiniband device */
75 75
 	struct ib_device *ibdev;
76 76
 	/** Completion queue */
@@ -135,8 +135,7 @@ static void ib_cmrc_shutdown ( struct process *process ) {
135 135
 static void ib_cmrc_close ( struct ib_cmrc_connection *cmrc, int rc ) {
136 136
 
137 137
 	/* Close data transfer interface */
138
-	xfer_nullify ( &cmrc->xfer );
139
-	xfer_close ( &cmrc->xfer, rc );
138
+	intf_shutdown ( &cmrc->xfer, rc );
140 139
 
141 140
 	/* Schedule shutdown process */
142 141
 	process_add ( &cmrc->shutdown );
@@ -263,16 +262,14 @@ static struct ib_completion_queue_operations ib_cmrc_completion_ops = {
263 262
 /**
264 263
  * Send data via CMRC
265 264
  *
266
- * @v xfer		Data transfer interface
265
+ * @v cmrc		CMRC connection
267 266
  * @v iobuf		Datagram I/O buffer
268 267
  * @v meta		Data transfer metadata
269 268
  * @ret rc		Return status code
270 269
  */
271
-static int ib_cmrc_xfer_deliver_iob ( struct xfer_interface *xfer,
272
-				      struct io_buffer *iobuf,
273
-				      struct xfer_metadata *meta __unused ) {
274
-	struct ib_cmrc_connection *cmrc =
275
-		container_of ( xfer, struct ib_cmrc_connection, xfer );
270
+static int ib_cmrc_xfer_deliver ( struct ib_cmrc_connection *cmrc,
271
+				  struct io_buffer *iobuf,
272
+				  struct xfer_metadata *meta __unused ) {
276 273
 	int rc;
277 274
 
278 275
 	/* If no connection has yet been attempted, send this datagram
@@ -326,12 +323,10 @@ static int ib_cmrc_xfer_deliver_iob ( struct xfer_interface *xfer,
326 323
 /**
327 324
  * Check CMRC flow control window
328 325
  *
329
- * @v xfer		Data transfer interface
326
+ * @v cmrc		CMRC connection
330 327
  * @ret len		Length of window
331 328
  */
332
-static size_t ib_cmrc_xfer_window ( struct xfer_interface *xfer ) {
333
-	struct ib_cmrc_connection *cmrc =
334
-		container_of ( xfer, struct ib_cmrc_connection, xfer );
329
+static size_t ib_cmrc_xfer_window ( struct ib_cmrc_connection *cmrc ) {
335 330
 
336 331
 	/* We indicate a window only when we are successfully
337 332
 	 * connected.
@@ -339,30 +334,19 @@ static size_t ib_cmrc_xfer_window ( struct xfer_interface *xfer ) {
339 334
 	return ( cmrc->connected ? IB_MAX_PAYLOAD_SIZE : 0 );
340 335
 }
341 336
 
342
-/**
343
- * Close CMRC data-transfer interface
344
- *
345
- * @v xfer		Data transfer interface
346
- * @v rc		Reason for close
347
- */
348
-static void ib_cmrc_xfer_close ( struct xfer_interface *xfer, int rc ) {
349
-	struct ib_cmrc_connection *cmrc =
350
-		container_of ( xfer, struct ib_cmrc_connection, xfer );
351
-
352
-	DBGC ( cmrc, "CMRC %p closed: %s\n", cmrc, strerror ( rc ) );
353
-	ib_cmrc_close ( cmrc, rc );
354
-}
355
-
356 337
 /** CMRC data transfer interface operations */
357
-static struct xfer_interface_operations ib_cmrc_xfer_operations = {
358
-	.close		= ib_cmrc_xfer_close,
359
-	.vredirect	= ignore_xfer_vredirect,
360
-	.window		= ib_cmrc_xfer_window,
361
-	.alloc_iob	= default_xfer_alloc_iob,
362
-	.deliver_iob	= ib_cmrc_xfer_deliver_iob,
363
-	.deliver_raw	= xfer_deliver_as_iob,
338
+static struct interface_operation ib_cmrc_xfer_operations[] = {
339
+	INTF_OP ( xfer_deliver, struct ib_cmrc_connection *,
340
+		  ib_cmrc_xfer_deliver ),
341
+	INTF_OP ( xfer_window, struct ib_cmrc_connection *,
342
+		  ib_cmrc_xfer_window ),
343
+	INTF_OP ( intf_close, struct ib_cmrc_connection *, ib_cmrc_close ),
364 344
 };
365 345
 
346
+/** CMRC data transfer interface descriptor */
347
+static struct interface_descriptor ib_cmrc_xfer_desc =
348
+	INTF_DESC ( struct ib_cmrc_connection, xfer, ib_cmrc_xfer_operations );
349
+
366 350
 /**
367 351
  * Open CMRC connection
368 352
  *
@@ -372,7 +356,7 @@ static struct xfer_interface_operations ib_cmrc_xfer_operations = {
372 356
  * @v service_id	Service ID
373 357
  * @ret rc		Returns status code
374 358
  */
375
-int ib_cmrc_open ( struct xfer_interface *xfer, struct ib_device *ibdev,
359
+int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev,
376 360
 		   struct ib_gid *dgid, struct ib_gid_half *service_id ) {
377 361
 	struct ib_cmrc_connection *cmrc;
378 362
 	int rc;
@@ -384,7 +368,7 @@ int ib_cmrc_open ( struct xfer_interface *xfer, struct ib_device *ibdev,
384 368
 		goto err_alloc;
385 369
 	}
386 370
 	ref_init ( &cmrc->refcnt, NULL );
387
-	xfer_init ( &cmrc->xfer, &ib_cmrc_xfer_operations, &cmrc->refcnt );
371
+	intf_init ( &cmrc->xfer, &ib_cmrc_xfer_desc, &cmrc->refcnt );
388 372
 	cmrc->ibdev = ibdev;
389 373
 	memcpy ( &cmrc->dgid, dgid, sizeof ( cmrc->dgid ) );
390 374
 	memcpy ( &cmrc->service_id, service_id, sizeof ( cmrc->service_id ) );
@@ -422,7 +406,7 @@ int ib_cmrc_open ( struct xfer_interface *xfer, struct ib_device *ibdev,
422 406
 	/* Attach to parent interface, transfer reference (implicitly)
423 407
 	 * to our shutdown process, and return.
424 408
 	 */
425
-	xfer_plug_plug ( &cmrc->xfer, xfer );
409
+	intf_plug_plug ( &cmrc->xfer, xfer );
426 410
 	return 0;
427 411
 
428 412
 	ib_destroy_qp ( ibdev, cmrc->qp );

+ 23
- 29
src/net/tcp.c Переглянути файл

@@ -31,7 +31,7 @@ struct tcp_connection {
31 31
 	struct list_head list;
32 32
 
33 33
 	/** Data transfer interface */
34
-	struct xfer_interface xfer;
34
+	struct interface xfer;
35 35
 	/** Data transfer interface closed flag */
36 36
 	int xfer_closed;
37 37
 
@@ -92,7 +92,7 @@ struct tcp_connection {
92 92
 static LIST_HEAD ( tcp_conns );
93 93
 
94 94
 /* Forward declarations */
95
-static struct xfer_interface_operations tcp_xfer_operations;
95
+static struct interface_descriptor tcp_xfer_desc;
96 96
 static void tcp_expired ( struct retry_timer *timer, int over );
97 97
 static int tcp_rx_ack ( struct tcp_connection *tcp, uint32_t ack,
98 98
 			uint32_t win );
@@ -211,7 +211,7 @@ static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
211 211
  * @v local		Local socket address, or NULL
212 212
  * @ret rc		Return status code
213 213
  */
214
-static int tcp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
214
+static int tcp_open ( struct interface *xfer, struct sockaddr *peer,
215 215
 		      struct sockaddr *local ) {
216 216
 	struct sockaddr_tcpip *st_peer = ( struct sockaddr_tcpip * ) peer;
217 217
 	struct sockaddr_tcpip *st_local = ( struct sockaddr_tcpip * ) local;
@@ -225,7 +225,7 @@ static int tcp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
225 225
 		return -ENOMEM;
226 226
 	DBGC ( tcp, "TCP %p allocated\n", tcp );
227 227
 	ref_init ( &tcp->refcnt, NULL );
228
-	xfer_init ( &tcp->xfer, &tcp_xfer_operations, &tcp->refcnt );
228
+	intf_init ( &tcp->xfer, &tcp_xfer_desc, &tcp->refcnt );
229 229
 	timer_init ( &tcp->timer, tcp_expired );
230 230
 	tcp->prev_tcp_state = TCP_CLOSED;
231 231
 	tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN );
@@ -245,7 +245,7 @@ static int tcp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
245 245
 	/* Attach parent interface, transfer reference to connection
246 246
 	 * list and return
247 247
 	 */
248
-	xfer_plug_plug ( &tcp->xfer, xfer );
248
+	intf_plug_plug ( &tcp->xfer, xfer );
249 249
 	list_add ( &tcp->list, &tcp_conns );
250 250
 	return 0;
251 251
 
@@ -268,8 +268,7 @@ static void tcp_close ( struct tcp_connection *tcp, int rc ) {
268 268
 	struct io_buffer *tmp;
269 269
 
270 270
 	/* Close data transfer interface */
271
-	xfer_nullify ( &tcp->xfer );
272
-	xfer_close ( &tcp->xfer, rc );
271
+	intf_shutdown ( &tcp->xfer, rc );
273 272
 	tcp->xfer_closed = 1;
274 273
 
275 274
 	/* If we are in CLOSED, or have otherwise not yet received a
@@ -1044,12 +1043,10 @@ struct tcpip_protocol tcp_protocol __tcpip_protocol = {
1044 1043
 /**
1045 1044
  * Close interface
1046 1045
  *
1047
- * @v xfer		Data transfer interface
1046
+ * @v tcp		TCP connection
1048 1047
  * @v rc		Reason for close
1049 1048
  */
1050
-static void tcp_xfer_close ( struct xfer_interface *xfer, int rc ) {
1051
-	struct tcp_connection *tcp =
1052
-		container_of ( xfer, struct tcp_connection, xfer );
1049
+static void tcp_xfer_close ( struct tcp_connection *tcp, int rc ) {
1053 1050
 
1054 1051
 	/* Close data transfer interface */
1055 1052
 	tcp_close ( tcp, rc );
@@ -1061,12 +1058,10 @@ static void tcp_xfer_close ( struct xfer_interface *xfer, int rc ) {
1061 1058
 /**
1062 1059
  * Check flow control window
1063 1060
  *
1064
- * @v xfer		Data transfer interface
1061
+ * @v tcp		TCP connection
1065 1062
  * @ret len		Length of window
1066 1063
  */
1067
-static size_t tcp_xfer_window ( struct xfer_interface *xfer ) {
1068
-	struct tcp_connection *tcp =
1069
-		container_of ( xfer, struct tcp_connection, xfer );
1064
+static size_t tcp_xfer_window ( struct tcp_connection *tcp ) {
1070 1065
 
1071 1066
 	/* Not ready if data queue is non-empty.  This imposes a limit
1072 1067
 	 * of only one unACKed packet in the TX queue at any time; we
@@ -1082,16 +1077,14 @@ static size_t tcp_xfer_window ( struct xfer_interface *xfer ) {
1082 1077
 /**
1083 1078
  * Deliver datagram as I/O buffer
1084 1079
  *
1085
- * @v xfer		Data transfer interface
1080
+ * @v tcp		TCP connection
1086 1081
  * @v iobuf		Datagram I/O buffer
1087 1082
  * @v meta		Data transfer metadata
1088 1083
  * @ret rc		Return status code
1089 1084
  */
1090
-static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
1091
-				  struct io_buffer *iobuf,
1092
-				  struct xfer_metadata *meta __unused ) {
1093
-	struct tcp_connection *tcp =
1094
-		container_of ( xfer, struct tcp_connection, xfer );
1085
+static int tcp_xfer_deliver ( struct tcp_connection *tcp,
1086
+			      struct io_buffer *iobuf,
1087
+			      struct xfer_metadata *meta __unused ) {
1095 1088
 
1096 1089
 	/* Enqueue packet */
1097 1090
 	list_add_tail ( &iobuf->list, &tcp->queue );
@@ -1103,15 +1096,16 @@ static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
1103 1096
 }
1104 1097
 
1105 1098
 /** TCP data transfer interface operations */
1106
-static struct xfer_interface_operations tcp_xfer_operations = {
1107
-	.close		= tcp_xfer_close,
1108
-	.vredirect	= ignore_xfer_vredirect,
1109
-	.window		= tcp_xfer_window,
1110
-	.alloc_iob	= default_xfer_alloc_iob,
1111
-	.deliver_iob	= tcp_xfer_deliver_iob,
1112
-	.deliver_raw	= xfer_deliver_as_iob,
1099
+static struct interface_operation tcp_xfer_operations[] = {
1100
+	INTF_OP ( xfer_deliver, struct tcp_connection *, tcp_xfer_deliver ),
1101
+	INTF_OP ( xfer_window, struct tcp_connection *, tcp_xfer_window ),
1102
+	INTF_OP ( intf_close, struct tcp_connection *, tcp_xfer_close ),
1113 1103
 };
1114 1104
 
1105
+/** TCP data transfer interface descriptor */
1106
+static struct interface_descriptor tcp_xfer_desc =
1107
+	INTF_DESC ( struct tcp_connection, xfer, tcp_xfer_operations );
1108
+
1115 1109
 /***************************************************************************
1116 1110
  *
1117 1111
  * Openers
@@ -1136,7 +1130,7 @@ int tcp_sock_stream = TCP_SOCK_STREAM;
1136 1130
  * @v uri		URI
1137 1131
  * @ret rc		Return status code
1138 1132
  */
1139
-static int tcp_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
1133
+static int tcp_open_uri ( struct interface *xfer, struct uri *uri ) {
1140 1134
 	struct sockaddr_tcpip peer;
1141 1135
 
1142 1136
 	/* Sanity check */

+ 53
- 91
src/net/tcp/ftp.c Переглянути файл

@@ -8,6 +8,7 @@
8 8
 #include <ipxe/socket.h>
9 9
 #include <ipxe/tcpip.h>
10 10
 #include <ipxe/in.h>
11
+#include <ipxe/iobuf.h>
11 12
 #include <ipxe/xfer.h>
12 13
 #include <ipxe/open.h>
13 14
 #include <ipxe/uri.h>
@@ -48,14 +49,14 @@ struct ftp_request {
48 49
 	/** Reference counter */
49 50
 	struct refcnt refcnt;
50 51
 	/** Data transfer interface */
51
-	struct xfer_interface xfer;
52
+	struct interface xfer;
52 53
 
53 54
 	/** URI being fetched */
54 55
 	struct uri *uri;
55 56
 	/** FTP control channel interface */
56
-	struct xfer_interface control;
57
+	struct interface control;
57 58
 	/** FTP data channel interface */
58
-	struct xfer_interface data;
59
+	struct interface data;
59 60
 
60 61
 	/** Current state */
61 62
 	enum ftp_state state;
@@ -95,12 +96,9 @@ static void ftp_done ( struct ftp_request *ftp, int rc ) {
95 96
 	DBGC ( ftp, "FTP %p completed (%s)\n", ftp, strerror ( rc ) );
96 97
 
97 98
 	/* Close all data transfer interfaces */
98
-	xfer_nullify ( &ftp->xfer );
99
-	xfer_close ( &ftp->xfer, rc );
100
-	xfer_nullify ( &ftp->control );
101
-	xfer_close ( &ftp->control, rc );
102
-	xfer_nullify ( &ftp->data );
103
-	xfer_close ( &ftp->data, rc );
99
+	intf_shutdown ( &ftp->data, rc );
100
+	intf_shutdown ( &ftp->control, rc );
101
+	intf_shutdown ( &ftp->xfer, rc );
104 102
 }
105 103
 
106 104
 /*****************************************************************************
@@ -166,26 +164,6 @@ static struct ftp_control_string ftp_strings[] = {
166 164
 	[FTP_DONE]	= { NULL, NULL },
167 165
 };
168 166
 
169
-/**
170
- * Handle control channel being closed
171
- *
172
- * @v control		FTP control channel interface
173
- * @v rc		Reason for close
174
- *
175
- * When the control channel is closed, the data channel must also be
176
- * closed, if it is currently open.
177
- */
178
-static void ftp_control_close ( struct xfer_interface *control, int rc ) {
179
-	struct ftp_request *ftp =
180
-		container_of ( control, struct ftp_request, control );
181
-
182
-	DBGC ( ftp, "FTP %p control connection closed: %s\n",
183
-	       ftp, strerror ( rc ) );
184
-
185
-	/* Complete FTP operation */
186
-	ftp_done ( ftp, rc );
187
-}
188
-
189 167
 /**
190 168
  * Parse FTP byte sequence value
191 169
  *
@@ -298,23 +276,25 @@ static void ftp_reply ( struct ftp_request *ftp ) {
298 276
 /**
299 277
  * Handle new data arriving on FTP control channel
300 278
  *
301
- * @v control		FTP control channel interface
302
- * @v data		New data
303
- * @v len		Length of new data
279
+ * @v ftp		FTP request
280
+ * @v iob		I/O buffer
281
+ * @v meta		Data transfer metadata
282
+ * @ret rc		Return status code
304 283
  *
305 284
  * Data is collected until a complete line is received, at which point
306 285
  * its information is passed to ftp_reply().
307 286
  */
308
-static int ftp_control_deliver_raw ( struct xfer_interface *control,
309
-				     const void *data, size_t len ) {
310
-	struct ftp_request *ftp =
311
-		container_of ( control, struct ftp_request, control );
287
+static int ftp_control_deliver ( struct ftp_request *ftp,
288
+				 struct io_buffer *iobuf,
289
+				 struct xfer_metadata *meta __unused ) {
290
+	char *data = iobuf->data;
291
+	size_t len = iob_len ( iobuf );
312 292
 	char *recvbuf = ftp->recvbuf;
313 293
 	size_t recvsize = ftp->recvsize;
314 294
 	char c;
315 295
 	
316 296
 	while ( len-- ) {
317
-		c = * ( ( char * ) data++ );
297
+		c = *(data++);
318 298
 		switch ( c ) {
319 299
 		case '\r' :
320 300
 		case '\n' :
@@ -351,19 +331,22 @@ static int ftp_control_deliver_raw ( struct xfer_interface *control,
351 331
 	ftp->recvbuf = recvbuf;
352 332
 	ftp->recvsize = recvsize;
353 333
 
334
+	/* Free I/O buffer */
335
+	free_iob ( iobuf );
336
+
354 337
 	return 0;
355 338
 }
356 339
 
357
-/** FTP control channel operations */
358
-static struct xfer_interface_operations ftp_control_operations = {
359
-	.close		= ftp_control_close,
360
-	.vredirect	= xfer_vreopen,
361
-	.window		= unlimited_xfer_window,
362
-	.alloc_iob	= default_xfer_alloc_iob,
363
-	.deliver_iob	= xfer_deliver_as_raw,
364
-	.deliver_raw	= ftp_control_deliver_raw,
340
+/** FTP control channel interface operations */
341
+static struct interface_operation ftp_control_operations[] = {
342
+	INTF_OP ( xfer_deliver, struct ftp_request *, ftp_control_deliver ),
343
+	INTF_OP ( intf_close, struct ftp_request *, ftp_done ),
365 344
 };
366 345
 
346
+/** FTP control channel interface descriptor */
347
+static struct interface_descriptor ftp_control_desc =
348
+	INTF_DESC ( struct ftp_request, control, ftp_control_operations );
349
+
367 350
 /*****************************************************************************
368 351
  *
369 352
  * FTP data channel
@@ -373,7 +356,7 @@ static struct xfer_interface_operations ftp_control_operations = {
373 356
 /**
374 357
  * Handle FTP data channel being closed
375 358
  *
376
- * @v data		FTP data channel interface
359
+ * @v ftp		FTP request
377 360
  * @v rc		Reason for closure
378 361
  *
379 362
  * When the data channel is closed, the control channel should be left
@@ -382,9 +365,7 @@ static struct xfer_interface_operations ftp_control_operations = {
382 365
  *
383 366
  * If the data channel is closed due to an error, we abort the request.
384 367
  */
385
-static void ftp_data_closed ( struct xfer_interface *data, int rc ) {
386
-	struct ftp_request *ftp =
387
-		container_of ( data, struct ftp_request, data );
368
+static void ftp_data_closed ( struct ftp_request *ftp, int rc ) {
388 369
 
389 370
 	DBGC ( ftp, "FTP %p data connection closed: %s\n",
390 371
 	       ftp, strerror ( rc ) );
@@ -400,16 +381,14 @@ static void ftp_data_closed ( struct xfer_interface *data, int rc ) {
400 381
 /**
401 382
  * Handle data delivery via FTP data channel
402 383
  *
403
- * @v xfer		FTP data channel interface
384
+ * @v ftp		FTP request
404 385
  * @v iobuf		I/O buffer
405 386
  * @v meta		Data transfer metadata
406 387
  * @ret rc		Return status code
407 388
  */
408
-static int ftp_data_deliver_iob ( struct xfer_interface *data,
409
-				  struct io_buffer *iobuf,
410
-				  struct xfer_metadata *meta __unused ) {
411
-	struct ftp_request *ftp =
412
-		container_of ( data, struct ftp_request, data );
389
+static int ftp_data_deliver ( struct ftp_request *ftp,
390
+			      struct io_buffer *iobuf,
391
+			      struct xfer_metadata *meta __unused ) {
413 392
 	int rc;
414 393
 
415 394
 	if ( ( rc = xfer_deliver_iob ( &ftp->xfer, iobuf ) ) != 0 ) {
@@ -421,48 +400,31 @@ static int ftp_data_deliver_iob ( struct xfer_interface *data,
421 400
 	return 0;
422 401
 }
423 402
 
424
-/** FTP data channel operations */
425
-static struct xfer_interface_operations ftp_data_operations = {
426
-	.close		= ftp_data_closed,
427
-	.vredirect	= xfer_vreopen,
428
-	.window		= unlimited_xfer_window,
429
-	.alloc_iob	= default_xfer_alloc_iob,
430
-	.deliver_iob	= ftp_data_deliver_iob,
431
-	.deliver_raw	= xfer_deliver_as_iob,
403
+/** FTP data channel interface operations */
404
+static struct interface_operation ftp_data_operations[] = {
405
+	INTF_OP ( xfer_deliver, struct ftp_request *, ftp_data_deliver ),
406
+	INTF_OP ( intf_close, struct ftp_request *, ftp_data_closed ),
432 407
 };
433 408
 
409
+/** FTP data channel interface descriptor */
410
+static struct interface_descriptor ftp_data_desc =
411
+	INTF_DESC ( struct ftp_request, data, ftp_data_operations );
412
+
434 413
 /*****************************************************************************
435 414
  *
436 415
  * Data transfer interface
437 416
  *
438 417
  */
439 418
 
440
-/**
441
- * Close FTP data transfer interface
442
- *
443
- * @v xfer		FTP data transfer interface
444
- * @v rc		Reason for close
445
- */
446
-static void ftp_xfer_closed ( struct xfer_interface *xfer, int rc ) {
447
-	struct ftp_request *ftp =
448
-		container_of ( xfer, struct ftp_request, xfer );
449
-
450
-	DBGC ( ftp, "FTP %p data transfer interface closed: %s\n",
451
-	       ftp, strerror ( rc ) );
452
-	
453
-	ftp_done ( ftp, rc );
454
-}
455
-
456 419
 /** FTP data transfer interface operations */
457
-static struct xfer_interface_operations ftp_xfer_operations = {
458
-	.close		= ftp_xfer_closed,
459
-	.vredirect	= ignore_xfer_vredirect,
460
-	.window		= unlimited_xfer_window,
461
-	.alloc_iob	= default_xfer_alloc_iob,
462
-	.deliver_iob	= xfer_deliver_as_raw,
463
-	.deliver_raw	= ignore_xfer_deliver_raw,
420
+static struct interface_operation ftp_xfer_operations[] = {
421
+	INTF_OP ( intf_close, struct ftp_request *, ftp_done ),
464 422
 };
465 423
 
424
+/** FTP data transfer interface descriptor */
425
+static struct interface_descriptor ftp_xfer_desc =
426
+	INTF_DESC ( struct ftp_request, xfer, ftp_xfer_operations );
427
+
466 428
 /*****************************************************************************
467 429
  *
468 430
  * URI opener
@@ -476,7 +438,7 @@ static struct xfer_interface_operations ftp_xfer_operations = {
476 438
  * @v uri		Uniform Resource Identifier
477 439
  * @ret rc		Return status code
478 440
  */
479
-static int ftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
441
+static int ftp_open ( struct interface *xfer, struct uri *uri ) {
480 442
 	struct ftp_request *ftp;
481 443
 	struct sockaddr_tcpip server;
482 444
 	int rc;
@@ -492,10 +454,10 @@ static int ftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
492 454
 	if ( ! ftp )
493 455
 		return -ENOMEM;
494 456
 	ref_init ( &ftp->refcnt, ftp_free );
495
-	xfer_init ( &ftp->xfer, &ftp_xfer_operations, &ftp->refcnt );
457
+	intf_init ( &ftp->xfer, &ftp_xfer_desc, &ftp->refcnt );
458
+	intf_init ( &ftp->control, &ftp_control_desc, &ftp->refcnt );
459
+	intf_init ( &ftp->data, &ftp_data_desc, &ftp->refcnt );
496 460
 	ftp->uri = uri_get ( uri );
497
-	xfer_init ( &ftp->control, &ftp_control_operations, &ftp->refcnt );
498
-	xfer_init ( &ftp->data, &ftp_data_operations, &ftp->refcnt );
499 461
 	ftp->recvbuf = ftp->status_text;
500 462
 	ftp->recvsize = sizeof ( ftp->status_text ) - 1;
501 463
 
@@ -510,7 +472,7 @@ static int ftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
510 472
 		goto err;
511 473
 
512 474
 	/* Attach to parent interface, mortalise self, and return */
513
-	xfer_plug_plug ( &ftp->xfer, xfer );
475
+	intf_plug_plug ( &ftp->xfer, xfer );
514 476
 	ref_put ( &ftp->refcnt );
515 477
 	return 0;
516 478
 

+ 29
- 66
src/net/tcp/http.c Переглянути файл

@@ -64,12 +64,12 @@ struct http_request {
64 64
 	/** Reference count */
65 65
 	struct refcnt refcnt;
66 66
 	/** Data transfer interface */
67
-	struct xfer_interface xfer;
67
+	struct interface xfer;
68 68
 
69 69
 	/** URI being fetched */
70 70
 	struct uri *uri;
71 71
 	/** Transport layer interface */
72
-	struct xfer_interface socket;
72
+	struct interface socket;
73 73
 
74 74
 	/** TX process */
75 75
 	struct process process;
@@ -125,10 +125,8 @@ static void http_done ( struct http_request *http, int rc ) {
125 125
 	process_del ( &http->process );
126 126
 
127 127
 	/* Close all data transfer interfaces */
128
-	xfer_nullify ( &http->socket );
129
-	xfer_close ( &http->socket, rc );
130
-	xfer_nullify ( &http->xfer );
131
-	xfer_close ( &http->xfer, rc );
128
+	intf_shutdown ( &http->socket, rc );
129
+	intf_shutdown ( &http->xfer, rc );
132 130
 }
133 131
 
134 132
 /**
@@ -349,16 +347,14 @@ static int http_rx_data ( struct http_request *http,
349 347
 /**
350 348
  * Handle new data arriving via HTTP connection
351 349
  *
352
- * @v socket		Transport layer interface
350
+ * @v http		HTTP request
353 351
  * @v iobuf		I/O buffer
354 352
  * @v meta		Data transfer metadata
355 353
  * @ret rc		Return status code
356 354
  */
357
-static int http_socket_deliver_iob ( struct xfer_interface *socket,
358
-				     struct io_buffer *iobuf,
359
-				     struct xfer_metadata *meta __unused ) {
360
-	struct http_request *http =
361
-		container_of ( socket, struct http_request, socket );
355
+static int http_socket_deliver ( struct http_request *http,
356
+				 struct io_buffer *iobuf,
357
+				 struct xfer_metadata *meta __unused ) {
362 358
 	struct http_line_handler *lh;
363 359
 	char *line;
364 360
 	ssize_t len;
@@ -469,58 +465,25 @@ static void http_step ( struct process *process ) {
469 465
 	}
470 466
 }
471 467
 
472
-/**
473
- * HTTP connection closed by network stack
474
- *
475
- * @v socket		Transport layer interface
476
- * @v rc		Reason for close
477
- */
478
-static void http_socket_close ( struct xfer_interface *socket, int rc ) {
479
-	struct http_request *http =
480
-		container_of ( socket, struct http_request, socket );
481
-
482
-	DBGC ( http, "HTTP %p socket closed: %s\n",
483
-	       http, strerror ( rc ) );
484
-	
485
-	http_done ( http, rc );
486
-}
487
-
488
-/** HTTP socket operations */
489
-static struct xfer_interface_operations http_socket_operations = {
490
-	.close		= http_socket_close,
491
-	.vredirect	= xfer_vreopen,
492
-	.window		= unlimited_xfer_window,
493
-	.alloc_iob	= default_xfer_alloc_iob,
494
-	.deliver_iob	= http_socket_deliver_iob,
495
-	.deliver_raw	= xfer_deliver_as_iob,
468
+/** HTTP socket interface operations */
469
+static struct interface_operation http_socket_operations[] = {
470
+	INTF_OP ( xfer_deliver, struct http_request *, http_socket_deliver ),
471
+	INTF_OP ( intf_close, struct http_request *, http_done ),
496 472
 };
497 473
 
498
-/**
499
- * Close HTTP data transfer interface
500
- *
501
- * @v xfer		Data transfer interface
502
- * @v rc		Reason for close
503
- */
504
-static void http_xfer_close ( struct xfer_interface *xfer, int rc ) {
505
-	struct http_request *http =
506
-		container_of ( xfer, struct http_request, xfer );
507
-
508
-	DBGC ( http, "HTTP %p interface closed: %s\n",
509
-	       http, strerror ( rc ) );
510
-
511
-	http_done ( http, rc );
512
-}
474
+/** HTTP socket interface descriptor */
475
+static struct interface_descriptor http_socket_desc =
476
+	INTF_DESC ( struct http_request, socket, http_socket_operations );
513 477
 
514 478
 /** HTTP data transfer interface operations */
515
-static struct xfer_interface_operations http_xfer_operations = {
516
-	.close		= http_xfer_close,
517
-	.vredirect	= ignore_xfer_vredirect,
518
-	.window		= unlimited_xfer_window,
519
-	.alloc_iob	= default_xfer_alloc_iob,
520
-	.deliver_iob	= xfer_deliver_as_raw,
521
-	.deliver_raw	= ignore_xfer_deliver_raw,
479
+static struct interface_operation http_xfer_operations[] = {
480
+	INTF_OP ( intf_close, struct http_request *, http_done ),
522 481
 };
523 482
 
483
+/** HTTP data transfer interface descriptor */
484
+static struct interface_descriptor http_xfer_desc =
485
+	INTF_DESC ( struct http_request, xfer, http_xfer_operations );
486
+
524 487
 /**
525 488
  * Initiate an HTTP connection, with optional filter
526 489
  *
@@ -530,13 +493,13 @@ static struct xfer_interface_operations http_xfer_operations = {
530 493
  * @v filter		Filter to apply to socket, or NULL
531 494
  * @ret rc		Return status code
532 495
  */
533
-int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
496
+int http_open_filter ( struct interface *xfer, struct uri *uri,
534 497
 		       unsigned int default_port,
535
-		       int ( * filter ) ( struct xfer_interface *xfer,
536
-					  struct xfer_interface **next ) ) {
498
+		       int ( * filter ) ( struct interface *xfer,
499
+					  struct interface **next ) ) {
537 500
 	struct http_request *http;
538 501
 	struct sockaddr_tcpip server;
539
-	struct xfer_interface *socket;
502
+	struct interface *socket;
540 503
 	int rc;
541 504
 
542 505
 	/* Sanity checks */
@@ -548,9 +511,9 @@ int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
548 511
 	if ( ! http )
549 512
 		return -ENOMEM;
550 513
 	ref_init ( &http->refcnt, http_free );
551
-	xfer_init ( &http->xfer, &http_xfer_operations, &http->refcnt );
514
+	intf_init ( &http->xfer, &http_xfer_desc, &http->refcnt );
552 515
        	http->uri = uri_get ( uri );
553
-	xfer_init ( &http->socket, &http_socket_operations, &http->refcnt );
516
+	intf_init ( &http->socket, &http_socket_desc, &http->refcnt );
554 517
 	process_init ( &http->process, http_step, &http->refcnt );
555 518
 
556 519
 	/* Open socket */
@@ -567,7 +530,7 @@ int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
567 530
 		goto err;
568 531
 
569 532
 	/* Attach to parent interface, mortalise self, and return */
570
-	xfer_plug_plug ( &http->xfer, xfer );
533
+	intf_plug_plug ( &http->xfer, xfer );
571 534
 	ref_put ( &http->refcnt );
572 535
 	return 0;
573 536
 
@@ -586,7 +549,7 @@ int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
586 549
  * @v uri		Uniform Resource Identifier
587 550
  * @ret rc		Return status code
588 551
  */
589
-static int http_open ( struct xfer_interface *xfer, struct uri *uri ) {
552
+static int http_open ( struct interface *xfer, struct uri *uri ) {
590 553
 	return http_open_filter ( xfer, uri, HTTP_PORT, NULL );
591 554
 }
592 555
 

+ 1
- 1
src/net/tcp/https.c Переглянути файл

@@ -40,7 +40,7 @@ FEATURE ( FEATURE_PROTOCOL, "HTTPS", DHCP_EB_FEATURE_HTTPS, 1 );
40 40
  * @v uri		Uniform Resource Identifier
41 41
  * @ret rc		Return status code
42 42
  */
43
-static int https_open ( struct xfer_interface *xfer, struct uri *uri ) {
43
+static int https_open ( struct interface *xfer, struct uri *uri ) {
44 44
 	return http_open_filter ( xfer, uri, HTTPS_PORT, add_tls );
45 45
 }
46 46
 

+ 38
- 37
src/net/tcp/iscsi.c Переглянути файл

@@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
27 27
 #include <byteswap.h>
28 28
 #include <ipxe/vsprintf.h>
29 29
 #include <ipxe/socket.h>
30
+#include <ipxe/iobuf.h>
30 31
 #include <ipxe/xfer.h>
31 32
 #include <ipxe/open.h>
32 33
 #include <ipxe/scsi.h>
@@ -199,7 +200,7 @@ static int iscsi_open_connection ( struct iscsi_session *iscsi ) {
199 200
 static void iscsi_close_connection ( struct iscsi_session *iscsi, int rc ) {
200 201
 
201 202
 	/* Close all data transfer interfaces */
202
-	xfer_close ( &iscsi->socket, rc );
203
+	intf_restart ( &iscsi->socket, rc );
203 204
 
204 205
 	/* Clear connection status */
205 206
 	iscsi->status = 0;
@@ -1435,9 +1436,9 @@ static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
1435 1436
 /**
1436 1437
  * Receive new data
1437 1438
  *
1438
- * @v socket		Transport layer interface
1439
- * @v data		Received data
1440
- * @v len		Length of received data
1439
+ * @v iscsi		iSCSI session
1440
+ * @v iobuf		I/O buffer
1441
+ * @v meta		Data transfer metadata
1441 1442
  * @ret rc		Return status code
1442 1443
  *
1443 1444
  * This handles received PDUs.  The receive strategy is to fill in
@@ -1447,10 +1448,9 @@ static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
1447 1448
  * always has a full copy of the BHS available, even for portions of
1448 1449
  * the data in different packets to the BHS.
1449 1450
  */
1450
-static int iscsi_socket_deliver_raw ( struct xfer_interface *socket,
1451
-				      const void *data, size_t len ) {
1452
-	struct iscsi_session *iscsi =
1453
-		container_of ( socket, struct iscsi_session, socket );
1451
+static int iscsi_socket_deliver ( struct iscsi_session *iscsi,
1452
+				  struct io_buffer *iobuf,
1453
+				  struct xfer_metadata *meta __unused ) {
1454 1454
 	struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1455 1455
 	int ( * rx ) ( struct iscsi_session *iscsi, const void *data,
1456 1456
 		       size_t len, size_t remaining );
@@ -1483,48 +1483,52 @@ static int iscsi_socket_deliver_raw ( struct xfer_interface *socket,
1483 1483
 			break;
1484 1484
 		default:
1485 1485
 			assert ( 0 );
1486
-			return -EINVAL;
1486
+			rc = -EINVAL;
1487
+			goto done;
1487 1488
 		}
1488 1489
 
1489 1490
 		frag_len = iscsi->rx_len - iscsi->rx_offset;
1490
-		if ( frag_len > len )
1491
-			frag_len = len;
1491
+		if ( frag_len > iob_len ( iobuf ) )
1492
+			frag_len = iob_len ( iobuf );
1492 1493
 		remaining = iscsi->rx_len - iscsi->rx_offset - frag_len;
1493
-		if ( ( rc = rx ( iscsi, data, frag_len, remaining ) ) != 0 ) {
1494
+		if ( ( rc = rx ( iscsi, iobuf->data, frag_len,
1495
+				 remaining ) ) != 0 ) {
1494 1496
 			DBGC ( iscsi, "iSCSI %p could not process received "
1495 1497
 			       "data: %s\n", iscsi, strerror ( rc ) );
1496 1498
 			iscsi_close_connection ( iscsi, rc );
1497 1499
 			iscsi_scsi_done ( iscsi, rc );
1498
-			return rc;
1500
+			goto done;
1499 1501
 		}
1500 1502
 
1501 1503
 		iscsi->rx_offset += frag_len;
1502
-		data += frag_len;
1503
-		len -= frag_len;
1504
+		iob_pull ( iobuf, frag_len );
1504 1505
 
1505 1506
 		/* If all the data for this state has not yet been
1506 1507
 		 * received, stay in this state for now.
1507 1508
 		 */
1508
-		if ( iscsi->rx_offset != iscsi->rx_len )
1509
-			return 0;
1509
+		if ( iscsi->rx_offset != iscsi->rx_len ) {
1510
+			rc = 0;
1511
+			goto done;
1512
+		}
1510 1513
 
1511 1514
 		iscsi->rx_state = next_state;
1512 1515
 		iscsi->rx_offset = 0;
1513 1516
 	}
1514 1517
 
1515
-	return 0;
1518
+ done:
1519
+	/* Free I/O buffer */
1520
+	free_iob ( iobuf );
1521
+	return rc;
1516 1522
 }
1517 1523
 
1518 1524
 /**
1519 1525
  * Handle stream connection closure
1520 1526
  *
1521
- * @v socket		Transport layer interface
1527
+ * @v iscsi		iSCSI session
1522 1528
  * @v rc		Reason for close
1523 1529
  *
1524 1530
  */
1525
-static void iscsi_socket_close ( struct xfer_interface *socket, int rc ) {
1526
-	struct iscsi_session *iscsi =
1527
-		container_of ( socket, struct iscsi_session, socket );
1531
+static void iscsi_socket_close ( struct iscsi_session *iscsi, int rc ) {
1528 1532
 
1529 1533
 	/* Even a graceful close counts as an error for iSCSI */
1530 1534
 	if ( ! rc )
@@ -1552,15 +1556,13 @@ static void iscsi_socket_close ( struct xfer_interface *socket, int rc ) {
1552 1556
 /**
1553 1557
  * Handle redirection event
1554 1558
  *
1555
- * @v socket		Transport layer interface
1559
+ * @v iscsi		iSCSI session
1556 1560
  * @v type		Location type
1557 1561
  * @v args		Remaining arguments depend upon location type
1558 1562
  * @ret rc		Return status code
1559 1563
  */
1560
-static int iscsi_vredirect ( struct xfer_interface *socket, int type,
1564
+static int iscsi_vredirect ( struct iscsi_session *iscsi, int type,
1561 1565
 			     va_list args ) {
1562
-	struct iscsi_session *iscsi =
1563
-		container_of ( socket, struct iscsi_session, socket );
1564 1566
 	va_list tmp;
1565 1567
 	struct sockaddr *peer;
1566 1568
 
@@ -1578,20 +1580,20 @@ static int iscsi_vredirect ( struct xfer_interface *socket, int type,
1578 1580
 		va_end ( tmp );
1579 1581
 	}
1580 1582
 
1581
-	return xfer_vreopen ( socket, type, args );
1583
+	return xfer_vreopen ( &iscsi->socket, type, args );
1582 1584
 }
1583 1585
 			     
1584 1586
 
1585
-/** iSCSI socket operations */
1586
-static struct xfer_interface_operations iscsi_socket_operations = {
1587
-	.close		= iscsi_socket_close,
1588
-	.vredirect	= iscsi_vredirect,
1589
-	.window		= unlimited_xfer_window,
1590
-	.alloc_iob	= default_xfer_alloc_iob,
1591
-	.deliver_iob	= xfer_deliver_as_raw,
1592
-	.deliver_raw	= iscsi_socket_deliver_raw,
1587
+/** iSCSI socket interface operations */
1588
+static struct interface_operation iscsi_socket_operations[] = {
1589
+	INTF_OP ( xfer_deliver, struct iscsi_session *, iscsi_socket_deliver ),
1590
+	INTF_OP ( xfer_vredirect, struct iscsi_session *, iscsi_vredirect ),
1591
+	INTF_OP ( intf_close, struct iscsi_session *, iscsi_socket_close ),
1593 1592
 };
1594 1593
 
1594
+/** iSCSI socket interface descriptor */
1595
+static struct interface_descriptor iscsi_socket_desc =
1596
+	INTF_DESC ( struct iscsi_session, socket, iscsi_socket_operations );
1595 1597
 
1596 1598
 /****************************************************************************
1597 1599
  *
@@ -1641,7 +1643,6 @@ void iscsi_detach ( struct scsi_device *scsi ) {
1641 1643
 	struct iscsi_session *iscsi =
1642 1644
 		container_of ( scsi->backend, struct iscsi_session, refcnt );
1643 1645
 
1644
-	xfer_nullify ( &iscsi->socket );
1645 1646
 	iscsi_close_connection ( iscsi, 0 );
1646 1647
 	process_del ( &iscsi->process );
1647 1648
 	scsi->command = scsi_detached_command;
@@ -1793,7 +1794,7 @@ int iscsi_attach ( struct scsi_device *scsi, const char *root_path ) {
1793 1794
 	if ( ! iscsi )
1794 1795
 		return -ENOMEM;
1795 1796
 	ref_init ( &iscsi->refcnt, iscsi_free );
1796
-	xfer_init ( &iscsi->socket, &iscsi_socket_operations, &iscsi->refcnt );
1797
+	intf_init ( &iscsi->socket, &iscsi_socket_desc, &iscsi->refcnt );
1797 1798
 	process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
1798 1799
 
1799 1800
 	/* Parse root path */

+ 72
- 92
src/net/tls.c Переглянути файл

@@ -35,9 +35,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 35
 #include <ipxe/sha1.h>
36 36
 #include <ipxe/aes.h>
37 37
 #include <ipxe/rsa.h>
38
+#include <ipxe/iobuf.h>
38 39
 #include <ipxe/xfer.h>
39 40
 #include <ipxe/open.h>
40
-#include <ipxe/filter.h>
41 41
 #include <ipxe/asn1.h>
42 42
 #include <ipxe/x509.h>
43 43
 #include <ipxe/tls.h>
@@ -107,10 +107,8 @@ static void tls_close ( struct tls_session *tls, int rc ) {
107 107
 	process_del ( &tls->process );
108 108
 	
109 109
 	/* Close ciphertext and plaintext streams */
110
-	xfer_nullify ( &tls->cipherstream.xfer );
111
-	xfer_close ( &tls->cipherstream.xfer, rc );
112
-	xfer_nullify ( &tls->plainstream.xfer );
113
-	xfer_close ( &tls->plainstream.xfer, rc );
110
+	intf_shutdown ( &tls->cipherstream, rc );
111
+	intf_shutdown ( &tls->plainstream, rc );
114 112
 }
115 113
 
116 114
 /******************************************************************************
@@ -1030,7 +1028,7 @@ static int tls_new_record ( struct tls_session *tls,
1030 1028
 	case TLS_TYPE_HANDSHAKE:
1031 1029
 		return tls_new_handshake ( tls, data, len );
1032 1030
 	case TLS_TYPE_DATA:
1033
-		return xfer_deliver_raw ( &tls->plainstream.xfer, data, len );
1031
+		return xfer_deliver_raw ( &tls->plainstream, data, len );
1034 1032
 	default:
1035 1033
 		/* RFC4346 says that we should just ignore unknown
1036 1034
 		 * record types.
@@ -1209,8 +1207,7 @@ static int tls_send_plaintext ( struct tls_session *tls, unsigned int type,
1209 1207
 
1210 1208
 	/* Allocate ciphertext */
1211 1209
 	ciphertext_len = ( sizeof ( *tlshdr ) + plaintext_len );
1212
-	ciphertext = xfer_alloc_iob ( &tls->cipherstream.xfer,
1213
-				      ciphertext_len );
1210
+	ciphertext = xfer_alloc_iob ( &tls->cipherstream, ciphertext_len );
1214 1211
 	if ( ! ciphertext ) {
1215 1212
 		DBGC ( tls, "TLS %p could not allocate %zd bytes for "
1216 1213
 		       "ciphertext\n", tls, ciphertext_len );
@@ -1234,9 +1231,8 @@ static int tls_send_plaintext ( struct tls_session *tls, unsigned int type,
1234 1231
 	plaintext = NULL;
1235 1232
 
1236 1233
 	/* Send ciphertext */
1237
-	rc = xfer_deliver_iob ( &tls->cipherstream.xfer, ciphertext );
1238
-	ciphertext = NULL;
1239
-	if ( rc != 0 ) {
1234
+	if ( ( rc = xfer_deliver_iob ( &tls->cipherstream,
1235
+				       iob_disown ( ciphertext ) ) ) != 0 ) {
1240 1236
 		DBGC ( tls, "TLS %p could not deliver ciphertext: %s\n",
1241 1237
 		       tls, strerror ( rc ) );
1242 1238
 		goto done;
@@ -1435,66 +1431,61 @@ static int tls_new_ciphertext ( struct tls_session *tls,
1435 1431
  ******************************************************************************
1436 1432
  */
1437 1433
 
1438
-/**
1439
- * Close interface
1440
- *
1441
- * @v xfer		Plainstream data transfer interface
1442
- * @v rc		Reason for close
1443
- */
1444
-static void tls_plainstream_close ( struct xfer_interface *xfer, int rc ) {
1445
-	struct tls_session *tls =
1446
-		container_of ( xfer, struct tls_session, plainstream.xfer );
1447
-
1448
-	tls_close ( tls, rc );
1449
-}
1450
-
1451 1434
 /**
1452 1435
  * Check flow control window
1453 1436
  *
1454
- * @v xfer		Plainstream data transfer interface
1437
+ * @v tls		TLS session
1455 1438
  * @ret len		Length of window
1456 1439
  */
1457
-static size_t tls_plainstream_window ( struct xfer_interface *xfer ) {
1458
-	struct tls_session *tls =
1459
-		container_of ( xfer, struct tls_session, plainstream.xfer );
1440
+static size_t tls_plainstream_window ( struct tls_session *tls ) {
1460 1441
 
1461 1442
 	/* Block window unless we are ready to accept data */
1462 1443
 	if ( tls->tx_state != TLS_TX_DATA )
1463 1444
 		return 0;
1464 1445
 
1465
-	return filter_window ( xfer );
1446
+	return xfer_window ( &tls->cipherstream );
1466 1447
 }
1467 1448
 
1468 1449
 /**
1469 1450
  * Deliver datagram as raw data
1470 1451
  *
1471
- * @v xfer		Plainstream data transfer interface
1472
- * @v data		Data buffer
1473
- * @v len		Length of data buffer
1452
+ * @v tls		TLS session
1453
+ * @v iobuf		I/O buffer
1454
+ * @v meta		Data transfer metadata
1474 1455
  * @ret rc		Return status code
1475 1456
  */
1476
-static int tls_plainstream_deliver_raw ( struct xfer_interface *xfer,
1477
-					 const void *data, size_t len ) {
1478
-	struct tls_session *tls =
1479
-		container_of ( xfer, struct tls_session, plainstream.xfer );
1457
+static int tls_plainstream_deliver ( struct tls_session *tls,
1458
+				     struct io_buffer *iobuf,
1459
+				     struct xfer_metadata *meta __unused ) {
1460
+	int rc;
1480 1461
 	
1481 1462
 	/* Refuse unless we are ready to accept data */
1482
-	if ( tls->tx_state != TLS_TX_DATA )
1483
-		return -ENOTCONN;
1463
+	if ( tls->tx_state != TLS_TX_DATA ) {
1464
+		rc = -ENOTCONN;
1465
+		goto done;
1466
+	}
1467
+
1468
+	if ( ( rc = tls_send_plaintext ( tls, TLS_TYPE_DATA, iobuf->data,
1469
+					 iob_len ( iobuf ) ) ) != 0 )
1470
+		goto done;
1484 1471
 
1485
-	return tls_send_plaintext ( tls, TLS_TYPE_DATA, data, len );
1472
+ done:
1473
+	free_iob ( iobuf );
1474
+	return rc;
1486 1475
 }
1487 1476
 
1488
-/** TLS plaintext stream operations */
1489
-static struct xfer_interface_operations tls_plainstream_operations = {
1490
-	.close		= tls_plainstream_close,
1491
-	.vredirect	= ignore_xfer_vredirect,
1492
-	.window		= tls_plainstream_window,
1493
-	.alloc_iob	= default_xfer_alloc_iob,
1494
-	.deliver_iob	= xfer_deliver_as_raw,
1495
-	.deliver_raw	= tls_plainstream_deliver_raw,
1477
+/** TLS plaintext stream interface operations */
1478
+static struct interface_operation tls_plainstream_ops[] = {
1479
+	INTF_OP ( xfer_deliver, struct tls_session *, tls_plainstream_deliver ),
1480
+	INTF_OP ( xfer_window, struct tls_session *, tls_plainstream_window ),
1481
+	INTF_OP ( intf_close, struct tls_session *, tls_close ),
1496 1482
 };
1497 1483
 
1484
+/** TLS plaintext stream interface descriptor */
1485
+static struct interface_descriptor tls_plainstream_desc =
1486
+	INTF_DESC_PASSTHRU ( struct tls_session, plainstream,
1487
+			     tls_plainstream_ops, cipherstream );
1488
+
1498 1489
 /******************************************************************************
1499 1490
  *
1500 1491
  * Ciphertext stream operations
@@ -1502,19 +1493,6 @@ static struct xfer_interface_operations tls_plainstream_operations = {
1502 1493
  ******************************************************************************
1503 1494
  */
1504 1495
 
1505
-/**
1506
- * Close interface
1507
- *
1508
- * @v xfer		Plainstream data transfer interface
1509
- * @v rc		Reason for close
1510
- */
1511
-static void tls_cipherstream_close ( struct xfer_interface *xfer, int rc ) {
1512
-	struct tls_session *tls =
1513
-		container_of ( xfer, struct tls_session, cipherstream.xfer );
1514
-
1515
-	tls_close ( tls, rc );
1516
-}
1517
-
1518 1496
 /**
1519 1497
  * Handle received TLS header
1520 1498
  *
@@ -1569,22 +1547,21 @@ static int tls_newdata_process_data ( struct tls_session *tls ) {
1569 1547
 /**
1570 1548
  * Receive new ciphertext
1571 1549
  *
1572
- * @v app		Stream application
1573
- * @v data		Data received
1574
- * @v len		Length of received data
1550
+ * @v tls		TLS session
1551
+ * @v iobuf		I/O buffer
1552
+ * @v meta		Data transfer metadat
1575 1553
  * @ret rc		Return status code
1576 1554
  */
1577
-static int tls_cipherstream_deliver_raw ( struct xfer_interface *xfer,
1578
-					  const void *data, size_t len ) {
1579
-	struct tls_session *tls = 
1580
-		container_of ( xfer, struct tls_session, cipherstream.xfer );
1555
+static int tls_cipherstream_deliver ( struct tls_session *tls,
1556
+				      struct io_buffer *iobuf,
1557
+				      struct xfer_metadata *xfer __unused ) {
1581 1558
 	size_t frag_len;
1582 1559
 	void *buf;
1583 1560
 	size_t buf_len;
1584 1561
 	int ( * process ) ( struct tls_session *tls );
1585 1562
 	int rc;
1586 1563
 
1587
-	while ( len ) {
1564
+	while ( iob_len ( iobuf ) ) {
1588 1565
 		/* Select buffer according to current state */
1589 1566
 		switch ( tls->rx_state ) {
1590 1567
 		case TLS_RX_HEADER:
@@ -1599,41 +1576,46 @@ static int tls_cipherstream_deliver_raw ( struct xfer_interface *xfer,
1599 1576
 			break;
1600 1577
 		default:
1601 1578
 			assert ( 0 );
1602
-			return -EINVAL;
1579
+			rc = -EINVAL;
1580
+			goto done;
1603 1581
 		}
1604 1582
 
1605 1583
 		/* Copy data portion to buffer */
1606 1584
 		frag_len = ( buf_len - tls->rx_rcvd );
1607
-		if ( frag_len > len )
1608
-			frag_len = len;
1609
-		memcpy ( ( buf + tls->rx_rcvd ), data, frag_len );
1585
+		if ( frag_len > iob_len  ( iobuf ) )
1586
+			frag_len = iob_len ( iobuf );
1587
+		memcpy ( ( buf + tls->rx_rcvd ), iobuf->data, frag_len );
1610 1588
 		tls->rx_rcvd += frag_len;
1611
-		data += frag_len;
1612
-		len -= frag_len;
1589
+		iob_pull ( iobuf, frag_len );
1613 1590
 
1614 1591
 		/* Process data if buffer is now full */
1615 1592
 		if ( tls->rx_rcvd == buf_len ) {
1616 1593
 			if ( ( rc = process ( tls ) ) != 0 ) {
1617 1594
 				tls_close ( tls, rc );
1618
-				return rc;
1595
+				goto done;
1619 1596
 			}
1620 1597
 			tls->rx_rcvd = 0;
1621 1598
 		}
1622 1599
 	}
1600
+	rc = 0;
1623 1601
 
1624
-	return 0;
1602
+ done:
1603
+	free_iob ( iobuf );
1604
+	return rc;
1625 1605
 }
1626 1606
 
1627
-/** TLS ciphertext stream operations */
1628
-static struct xfer_interface_operations tls_cipherstream_operations = {
1629
-	.close		= tls_cipherstream_close,
1630
-	.vredirect	= xfer_vreopen,
1631
-	.window		= filter_window,
1632
-	.alloc_iob	= default_xfer_alloc_iob,
1633
-	.deliver_iob	= xfer_deliver_as_raw,
1634
-	.deliver_raw	= tls_cipherstream_deliver_raw,
1607
+/** TLS ciphertext stream interface operations */
1608
+static struct interface_operation tls_cipherstream_ops[] = {
1609
+	INTF_OP ( xfer_deliver, struct tls_session *,
1610
+		  tls_cipherstream_deliver ),
1611
+	INTF_OP ( intf_close, struct tls_session *, tls_close ),
1635 1612
 };
1636 1613
 
1614
+/** TLS ciphertext stream interface descriptor */
1615
+static struct interface_descriptor tls_cipherstream_desc =
1616
+	INTF_DESC_PASSTHRU ( struct tls_session, cipherstream,
1617
+			     tls_cipherstream_ops, plainstream );
1618
+
1637 1619
 /******************************************************************************
1638 1620
  *
1639 1621
  * Controlling process
@@ -1652,7 +1634,7 @@ static void tls_step ( struct process *process ) {
1652 1634
 	int rc;
1653 1635
 
1654 1636
 	/* Wait for cipherstream to become ready */
1655
-	if ( ! xfer_window ( &tls->cipherstream.xfer ) )
1637
+	if ( ! xfer_window ( &tls->cipherstream ) )
1656 1638
 		return;
1657 1639
 
1658 1640
 	switch ( tls->tx_state ) {
@@ -1723,7 +1705,7 @@ static void tls_step ( struct process *process ) {
1723 1705
  ******************************************************************************
1724 1706
  */
1725 1707
 
1726
-int add_tls ( struct xfer_interface *xfer, struct xfer_interface **next ) {
1708
+int add_tls ( struct interface *xfer, struct interface **next ) {
1727 1709
 	struct tls_session *tls;
1728 1710
 
1729 1711
 	/* Allocate and initialise TLS structure */
@@ -1732,9 +1714,8 @@ int add_tls ( struct xfer_interface *xfer, struct xfer_interface **next ) {
1732 1714
 		return -ENOMEM;
1733 1715
 	memset ( tls, 0, sizeof ( *tls ) );
1734 1716
 	ref_init ( &tls->refcnt, free_tls );
1735
-	filter_init ( &tls->plainstream, &tls_plainstream_operations,
1736
-		      &tls->cipherstream, &tls_cipherstream_operations,
1737
-		      &tls->refcnt );
1717
+	intf_init ( &tls->plainstream, &tls_plainstream_desc, &tls->refcnt );
1718
+	intf_init ( &tls->cipherstream, &tls_cipherstream_desc, &tls->refcnt );
1738 1719
 	tls_clear_cipher ( tls, &tls->tx_cipherspec );
1739 1720
 	tls_clear_cipher ( tls, &tls->tx_cipherspec_pending );
1740 1721
 	tls_clear_cipher ( tls, &tls->rx_cipherspec );
@@ -1751,9 +1732,8 @@ int add_tls ( struct xfer_interface *xfer, struct xfer_interface **next ) {
1751 1732
 	process_init ( &tls->process, tls_step, &tls->refcnt );
1752 1733
 
1753 1734
 	/* Attach to parent interface, mortalise self, and return */
1754
-	xfer_plug_plug ( &tls->plainstream.xfer, xfer );
1755
-	*next = &tls->cipherstream.xfer;
1735
+	intf_plug_plug ( &tls->plainstream, xfer );
1736
+	*next = &tls->cipherstream;
1756 1737
 	ref_put ( &tls->refcnt );
1757 1738
 	return 0;
1758 1739
 }
1759
-

+ 25
- 43
src/net/udp.c Переглянути файл

@@ -29,7 +29,7 @@ struct udp_connection {
29 29
 	struct list_head list;
30 30
 
31 31
 	/** Data transfer interface */
32
-	struct xfer_interface xfer;
32
+	struct interface xfer;
33 33
 
34 34
 	/** Local socket address */
35 35
 	struct sockaddr_tcpip local;
@@ -43,7 +43,7 @@ struct udp_connection {
43 43
 static LIST_HEAD ( udp_conns );
44 44
 
45 45
 /* Forward declatations */
46
-static struct xfer_interface_operations udp_xfer_operations;
46
+static struct interface_descriptor udp_xfer_desc;
47 47
 struct tcpip_protocol udp_protocol;
48 48
 
49 49
 /**
@@ -97,7 +97,7 @@ static int udp_bind ( struct udp_connection *udp ) {
97 97
  * @v promisc		Socket is promiscuous
98 98
  * @ret rc		Return status code
99 99
  */
100
-static int udp_open_common ( struct xfer_interface *xfer,
100
+static int udp_open_common ( struct interface *xfer,
101 101
 			     struct sockaddr *peer, struct sockaddr *local,
102 102
 			     int promisc ) {
103 103
 	struct sockaddr_tcpip *st_peer = ( struct sockaddr_tcpip * ) peer;
@@ -111,7 +111,7 @@ static int udp_open_common ( struct xfer_interface *xfer,
111 111
 		return -ENOMEM;
112 112
 	DBGC ( udp, "UDP %p allocated\n", udp );
113 113
 	ref_init ( &udp->refcnt, NULL );
114
-	xfer_init ( &udp->xfer, &udp_xfer_operations, &udp->refcnt );
114
+	intf_init ( &udp->xfer, &udp_xfer_desc, &udp->refcnt );
115 115
 	if ( st_peer )
116 116
 		memcpy ( &udp->peer, st_peer, sizeof ( udp->peer ) );
117 117
 	if ( st_local )
@@ -126,7 +126,7 @@ static int udp_open_common ( struct xfer_interface *xfer,
126 126
 	/* Attach parent interface, transfer reference to connection
127 127
 	 * list and return
128 128
 	 */
129
-	xfer_plug_plug ( &udp->xfer, xfer );
129
+	intf_plug_plug ( &udp->xfer, xfer );
130 130
 	list_add ( &udp->list, &udp_conns );
131 131
 	return 0;
132 132
 
@@ -143,7 +143,7 @@ static int udp_open_common ( struct xfer_interface *xfer,
143 143
  * @v local		Local socket address, or NULL
144 144
  * @ret rc		Return status code
145 145
  */
146
-int udp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
146
+int udp_open ( struct interface *xfer, struct sockaddr *peer,
147 147
 	       struct sockaddr *local ) {
148 148
 	return udp_open_common ( xfer, peer, local, 0 );
149 149
 }
@@ -157,7 +157,7 @@ int udp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
157 157
  * Promiscuous UDP connections are required in order to support the
158 158
  * PXE API.
159 159
  */
160
-int udp_open_promisc ( struct xfer_interface *xfer ) {
160
+int udp_open_promisc ( struct interface *xfer ) {
161 161
 	return udp_open_common ( xfer, NULL, NULL, 1 );
162 162
 }
163 163
 
@@ -170,8 +170,7 @@ int udp_open_promisc ( struct xfer_interface *xfer ) {
170 170
 static void udp_close ( struct udp_connection *udp, int rc ) {
171 171
 
172 172
 	/* Close data transfer interface */
173
-	xfer_nullify ( &udp->xfer );
174
-	xfer_close ( &udp->xfer, rc );
173
+	intf_shutdown ( &udp->xfer, rc );
175 174
 
176 175
 	/* Remove from list of connections and drop list's reference */
177 176
 	list_del ( &udp->list );
@@ -331,7 +330,7 @@ static int udp_rx ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
331 330
 	memset ( &meta, 0, sizeof ( meta ) );
332 331
 	meta.src = ( struct sockaddr * ) st_src;
333 332
 	meta.dest = ( struct sockaddr * ) st_dest;
334
-	rc = xfer_deliver_iob_meta ( &udp->xfer, iob_disown ( iobuf ), &meta );
333
+	rc = xfer_deliver ( &udp->xfer, iob_disown ( iobuf ), &meta );
335 334
 
336 335
  done:
337 336
 	free_iob ( iobuf );
@@ -351,31 +350,15 @@ struct tcpip_protocol udp_protocol __tcpip_protocol = {
351 350
  ***************************************************************************
352 351
  */
353 352
 
354
-/**
355
- * Close interface
356
- *
357
- * @v xfer		Data transfer interface
358
- * @v rc		Reason for close
359
- */
360
-static void udp_xfer_close ( struct xfer_interface *xfer, int rc ) {
361
-	struct udp_connection *udp =
362
-		container_of ( xfer, struct udp_connection, xfer );
363
-
364
-	/* Close connection */
365
-	udp_close ( udp, rc );
366
-}
367
-
368 353
 /**
369 354
  * Allocate I/O buffer for UDP
370 355
  *
371
- * @v xfer		Data transfer interface
356
+ * @v udp		UDP connection
372 357
  * @v len		Payload size
373 358
  * @ret iobuf		I/O buffer, or NULL
374 359
  */
375
-static struct io_buffer * udp_alloc_iob ( struct xfer_interface *xfer,
376
-					  size_t len ) {
377
-	struct udp_connection *udp =
378
-		container_of ( xfer, struct udp_connection, xfer );	
360
+static struct io_buffer * udp_xfer_alloc_iob ( struct udp_connection *udp,
361
+					       size_t len ) {
379 362
 	struct io_buffer *iobuf;
380 363
 
381 364
 	iobuf = alloc_iob ( UDP_MAX_HLEN + len );
@@ -391,16 +374,14 @@ static struct io_buffer * udp_alloc_iob ( struct xfer_interface *xfer,
391 374
 /**
392 375
  * Deliver datagram as I/O buffer
393 376
  *
394
- * @v xfer		Data transfer interface
377
+ * @v udp		UDP connection
395 378
  * @v iobuf		Datagram I/O buffer
396 379
  * @v meta		Data transfer metadata
397 380
  * @ret rc		Return status code
398 381
  */
399
-static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
400
-				  struct io_buffer *iobuf,
401
-				  struct xfer_metadata *meta ) {
402
-	struct udp_connection *udp =
403
-		container_of ( xfer, struct udp_connection, xfer );
382
+static int udp_xfer_deliver ( struct udp_connection *udp,
383
+			      struct io_buffer *iobuf,
384
+			      struct xfer_metadata *meta ) {
404 385
 
405 386
 	/* Transmit data, if possible */
406 387
 	udp_tx ( udp, iobuf, ( ( struct sockaddr_tcpip * ) meta->src ),
@@ -410,15 +391,16 @@ static int udp_xfer_deliver_iob ( struct xfer_interface *xfer,
410 391
 }
411 392
 
412 393
 /** UDP data transfer interface operations */
413
-static struct xfer_interface_operations udp_xfer_operations = {
414
-	.close		= udp_xfer_close,
415
-	.vredirect	= ignore_xfer_vredirect,
416
-	.window		= unlimited_xfer_window,
417
-	.alloc_iob	= udp_alloc_iob,
418
-	.deliver_iob	= udp_xfer_deliver_iob,
419
-	.deliver_raw	= xfer_deliver_as_iob,
394
+static struct interface_operation udp_xfer_operations[] = {
395
+	INTF_OP ( xfer_deliver, struct udp_connection *, udp_xfer_deliver ),
396
+	INTF_OP ( xfer_alloc_iob, struct udp_connection *, udp_xfer_alloc_iob ),
397
+	INTF_OP ( intf_close, struct udp_connection *, udp_close ),
420 398
 };
421 399
 
400
+/** UDP data transfer interface descriptor */
401
+static struct interface_descriptor udp_xfer_desc =
402
+	INTF_DESC ( struct udp_connection, xfer, udp_xfer_operations );
403
+
422 404
 /***************************************************************************
423 405
  *
424 406
  * Openers
@@ -443,7 +425,7 @@ int udp_sock_dgram = UDP_SOCK_DGRAM;
443 425
  * @v uri		URI
444 426
  * @ret rc		Return status code
445 427
  */
446
-static int udp_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
428
+static int udp_open_uri ( struct interface *xfer, struct uri *uri ) {
447 429
 	struct sockaddr_tcpip peer;
448 430
 
449 431
 	/* Sanity check */

+ 17
- 20
src/net/udp/dhcp.c Переглянути файл

@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
26 26
 #include <assert.h>
27 27
 #include <byteswap.h>
28 28
 #include <ipxe/if_ether.h>
29
+#include <ipxe/iobuf.h>
29 30
 #include <ipxe/netdevice.h>
30 31
 #include <ipxe/device.h>
31 32
 #include <ipxe/xfer.h>
@@ -240,7 +241,7 @@ struct dhcp_session {
240 241
 	/** Job control interface */
241 242
 	struct interface job;
242 243
 	/** Data transfer interface */
243
-	struct xfer_interface xfer;
244
+	struct interface xfer;
244 245
 
245 246
 	/** Network device being configured */
246 247
 	struct net_device *netdev;
@@ -298,8 +299,7 @@ static void dhcp_finished ( struct dhcp_session *dhcp, int rc ) {
298 299
 	stop_timer ( &dhcp->timer );
299 300
 
300 301
 	/* Shut down interfaces */
301
-	xfer_nullify ( &dhcp->xfer );
302
-	xfer_close ( &dhcp->xfer, rc );
302
+	intf_shutdown ( &dhcp->xfer, rc );
303 303
 	intf_shutdown ( &dhcp->job, rc );
304 304
 }
305 305
 
@@ -1241,8 +1241,8 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) {
1241 1241
 
1242 1242
 	/* Transmit the packet */
1243 1243
 	iob_put ( iobuf, dhcppkt.len );
1244
-	if ( ( rc = xfer_deliver_iob_meta ( &dhcp->xfer, iob_disown ( iobuf ),
1245
-					    &meta ) ) != 0 ) {
1244
+	if ( ( rc = xfer_deliver ( &dhcp->xfer, iob_disown ( iobuf ),
1245
+				   &meta ) ) != 0 ) {
1246 1246
 		DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",
1247 1247
 		       dhcp, strerror ( rc ) );
1248 1248
 		goto done;
@@ -1256,16 +1256,14 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) {
1256 1256
 /**
1257 1257
  * Receive new data
1258 1258
  *
1259
- * @v xfer 		Data transfer interface
1259
+ * @v dhcp		DHCP session
1260 1260
  * @v iobuf		I/O buffer
1261 1261
  * @v meta		Transfer metadata
1262 1262
  * @ret rc		Return status code
1263 1263
  */
1264
-static int dhcp_deliver_iob ( struct xfer_interface *xfer,
1265
-			      struct io_buffer *iobuf,
1266
-			      struct xfer_metadata *meta ) {
1267
-	struct dhcp_session *dhcp =
1268
-		container_of ( xfer, struct dhcp_session, xfer );
1264
+static int dhcp_deliver ( struct dhcp_session *dhcp,
1265
+			  struct io_buffer *iobuf,
1266
+			  struct xfer_metadata *meta ) {
1269 1267
 	struct sockaddr_in *peer;
1270 1268
 	size_t data_len;
1271 1269
 	struct dhcp_packet *dhcppkt;
@@ -1328,15 +1326,14 @@ static int dhcp_deliver_iob ( struct xfer_interface *xfer,
1328 1326
 }
1329 1327
 
1330 1328
 /** DHCP data transfer interface operations */
1331
-static struct xfer_interface_operations dhcp_xfer_operations = {
1332
-	.close		= ignore_xfer_close,
1333
-	.vredirect	= xfer_vreopen,
1334
-	.window		= unlimited_xfer_window,
1335
-	.alloc_iob	= default_xfer_alloc_iob,
1336
-	.deliver_iob	= dhcp_deliver_iob,
1337
-	.deliver_raw	= xfer_deliver_as_iob,
1329
+static struct interface_operation dhcp_xfer_operations[] = {
1330
+	INTF_OP ( xfer_deliver, struct dhcp_session *, dhcp_deliver ),
1338 1331
 };
1339 1332
 
1333
+/** DHCP data transfer interface descriptor */
1334
+static struct interface_descriptor dhcp_xfer_desc =
1335
+	INTF_DESC ( struct dhcp_session, xfer, dhcp_xfer_operations );
1336
+
1340 1337
 /**
1341 1338
  * Handle DHCP retry timer expiry
1342 1339
  *
@@ -1427,7 +1424,7 @@ int start_dhcp ( struct interface *job, struct net_device *netdev ) {
1427 1424
 		return -ENOMEM;
1428 1425
 	ref_init ( &dhcp->refcnt, dhcp_free );
1429 1426
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1430
-	xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
1427
+	intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1431 1428
 	timer_init ( &dhcp->timer, dhcp_timer_expired );
1432 1429
 	dhcp->netdev = netdev_get ( netdev );
1433 1430
 	dhcp->local.sin_family = AF_INET;
@@ -1530,7 +1527,7 @@ int start_pxebs ( struct interface *job, struct net_device *netdev,
1530 1527
 		return -ENOMEM;
1531 1528
 	ref_init ( &dhcp->refcnt, dhcp_free );
1532 1529
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1533
-	xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
1530
+	intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1534 1531
 	timer_init ( &dhcp->timer, dhcp_timer_expired );
1535 1532
 	dhcp->netdev = netdev_get ( netdev );
1536 1533
 	dhcp->local.sin_family = AF_INET;

+ 45
- 36
src/net/udp/dns.c Переглянути файл

@@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <errno.h>
29 29
 #include <byteswap.h>
30 30
 #include <ipxe/refcnt.h>
31
+#include <ipxe/iobuf.h>
31 32
 #include <ipxe/xfer.h>
32 33
 #include <ipxe/open.h>
33 34
 #include <ipxe/resolv.h>
@@ -60,7 +61,7 @@ struct dns_request {
60 61
 	/** Name resolution interface */
61 62
 	struct interface resolv;
62 63
 	/** Data transfer interface */
63
-	struct xfer_interface socket;
64
+	struct interface socket;
64 65
 	/** Retry timer */
65 66
 	struct retry_timer timer;
66 67
 
@@ -89,11 +90,8 @@ static void dns_done ( struct dns_request *dns, int rc ) {
89 90
 	/* Stop the retry timer */
90 91
 	stop_timer ( &dns->timer );
91 92
 
92
-	/* Close data transfer interface */
93
-	xfer_nullify ( &dns->socket );
94
-	xfer_close ( &dns->socket, rc );
95
-
96 93
 	/* Shut down interfaces */
94
+	intf_shutdown ( &dns->socket, rc );
97 95
 	intf_shutdown ( &dns->resolv, rc );
98 96
 }
99 97
 
@@ -322,25 +320,26 @@ static void dns_timer_expired ( struct retry_timer *timer, int fail ) {
322 320
 /**
323 321
  * Receive new data
324 322
  *
325
- * @v socket		UDP socket
326
- * @v data		DNS reply
327
- * @v len		Length of DNS reply
323
+ * @v dns		DNS request
324
+ * @v iobuf		I/O buffer
325
+ * @v meta		Data transfer metadata
328 326
  * @ret rc		Return status code
329 327
  */
330
-static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
331
-				  const void *data, size_t len ) {
332
-	struct dns_request *dns =
333
-		container_of ( socket, struct dns_request, socket );
334
-	const struct dns_header *reply = data;
328
+static int dns_xfer_deliver ( struct dns_request *dns,
329
+			      struct io_buffer *iobuf,
330
+			      struct xfer_metadata *meta __unused ) {
331
+	const struct dns_header *reply = iobuf->data;
335 332
 	union dns_rr_info *rr_info;
336 333
 	struct sockaddr_in *sin;
337 334
 	unsigned int qtype = dns->qinfo->qtype;
335
+	int rc;
338 336
 
339 337
 	/* Sanity check */
340
-	if ( len < sizeof ( *reply ) ) {
338
+	if ( iob_len ( iobuf ) < sizeof ( *reply ) ) {
341 339
 		DBGC ( dns, "DNS %p received underlength packet length %zd\n",
342
-		       dns, len );
343
-		return -EINVAL;
340
+		       dns, iob_len ( iobuf ) );
341
+		rc = -EINVAL;
342
+		goto done;
344 343
 	}
345 344
 
346 345
 	/* Check reply ID matches query ID */
@@ -348,7 +347,8 @@ static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
348 347
 		DBGC ( dns, "DNS %p received unexpected reply ID %d "
349 348
 		       "(wanted %d)\n", dns, ntohs ( reply->id ),
350 349
 		       ntohs ( dns->query.dns.id ) );
351
-		return -EINVAL;
350
+		rc = -EINVAL;
351
+		goto done;
352 352
 	}
353 353
 
354 354
 	DBGC ( dns, "DNS %p received reply ID %d\n", dns, ntohs ( reply->id ));
@@ -382,7 +382,8 @@ static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
382 382
 
383 383
 			/* Mark operation as complete */
384 384
 			dns_done ( dns, 0 );
385
-			return 0;
385
+			rc = 0;
386
+			goto done;
386 387
 
387 388
 		case htons ( DNS_TYPE_CNAME ):
388 389
 
@@ -399,7 +400,8 @@ static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
399 400
 				DBGC ( dns, "DNS %p recursion exceeded\n",
400 401
 				       dns );
401 402
 				dns_done ( dns, -ELOOP );
402
-				return 0;
403
+				rc = 0;
404
+				goto done;
403 405
 			}
404 406
 			break;
405 407
 
@@ -422,7 +424,8 @@ static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
422 424
 		DBGC ( dns, "DNS %p found no A record; trying CNAME\n", dns );
423 425
 		dns->qinfo->qtype = htons ( DNS_TYPE_CNAME );
424 426
 		dns_send_packet ( dns );
425
-		return 0;
427
+		rc = 0;
428
+		goto done;
426 429
 
427 430
 	case htons ( DNS_TYPE_CNAME ):
428 431
 		/* We asked for a CNAME record.  If we got a response
@@ -431,29 +434,35 @@ static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
431 434
 		 */
432 435
 		if ( dns->qinfo->qtype == htons ( DNS_TYPE_A ) ) {
433 436
 			dns_send_packet ( dns );
434
-			return 0;
437
+			rc = 0;
438
+			goto done;
435 439
 		} else {
436 440
 			DBGC ( dns, "DNS %p found no CNAME record\n", dns );
437 441
 			dns_done ( dns, -ENXIO );
438
-			return 0;
442
+			rc = 0;
443
+			goto done;
439 444
 		}
440 445
 
441 446
 	default:
442 447
 		assert ( 0 );
443 448
 		dns_done ( dns, -EINVAL );
444
-		return 0;
449
+		rc = -EINVAL;
450
+		goto done;
445 451
 	}
452
+
453
+ done:
454
+	/* Free I/O buffer */
455
+	free_iob ( iobuf );
456
+	return rc;
446 457
 }
447 458
 
448 459
 /**
449 460
  * Receive new data
450 461
  *
451
- * @v socket		UDP socket
462
+ * @v dns		DNS request
452 463
  * @v rc		Reason for close
453 464
  */
454
-static void dns_xfer_close ( struct xfer_interface *socket, int rc ) {
455
-	struct dns_request *dns =
456
-		container_of ( socket, struct dns_request, socket );
465
+static void dns_xfer_close ( struct dns_request *dns, int rc ) {
457 466
 
458 467
 	if ( ! rc )
459 468
 		rc = -ECONNABORTED;
@@ -461,16 +470,16 @@ static void dns_xfer_close ( struct xfer_interface *socket, int rc ) {
461 470
 	dns_done ( dns, rc );
462 471
 }
463 472
 
464
-/** DNS socket operations */
465
-static struct xfer_interface_operations dns_socket_operations = {
466
-	.close		= dns_xfer_close,
467
-	.vredirect	= xfer_vreopen,
468
-	.window		= unlimited_xfer_window,
469
-	.alloc_iob	= default_xfer_alloc_iob,
470
-	.deliver_iob	= xfer_deliver_as_raw,
471
-	.deliver_raw	= dns_xfer_deliver_raw,
473
+/** DNS socket interface operations */
474
+static struct interface_operation dns_socket_operations[] = {
475
+	INTF_OP ( xfer_deliver, struct dns_request *, dns_xfer_deliver ),
476
+	INTF_OP ( intf_close, struct dns_request *, dns_xfer_close ),
472 477
 };
473 478
 
479
+/** DNS socket interface descriptor */
480
+static struct interface_descriptor dns_socket_desc =
481
+	INTF_DESC ( struct dns_request, socket, dns_socket_operations );
482
+
474 483
 /** DNS resolver interface operations */
475 484
 static struct interface_operation dns_resolv_op[] = {
476 485
 	INTF_OP ( intf_close, struct dns_request *, dns_done ),
@@ -517,7 +526,7 @@ static int dns_resolv ( struct interface *resolv,
517 526
 	}
518 527
 	ref_init ( &dns->refcnt, NULL );
519 528
 	intf_init ( &dns->resolv, &dns_resolv_desc, &dns->refcnt );
520
-	xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
529
+	intf_init ( &dns->socket, &dns_socket_desc, &dns->refcnt );
521 530
 	timer_init ( &dns->timer, dns_timer_expired );
522 531
 	memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
523 532
 

+ 38
- 96
src/net/udp/slam.c Переглянути файл

@@ -119,11 +119,11 @@ struct slam_request {
119 119
 	struct refcnt refcnt;
120 120
 
121 121
 	/** Data transfer interface */
122
-	struct xfer_interface xfer;
122
+	struct interface xfer;
123 123
 	/** Unicast socket */
124
-	struct xfer_interface socket;
124
+	struct interface socket;
125 125
 	/** Multicast socket */
126
-	struct xfer_interface mc_socket;
126
+	struct interface mc_socket;
127 127
 
128 128
 	/** Master client retry timer */
129 129
 	struct retry_timer master_timer;
@@ -184,12 +184,9 @@ static void slam_finished ( struct slam_request *slam, int rc ) {
184 184
 	stop_timer ( &slam->slave_timer );
185 185
 
186 186
 	/* Close all data transfer interfaces */
187
-	xfer_nullify ( &slam->socket );
188
-	xfer_close ( &slam->socket, rc );
189
-	xfer_nullify ( &slam->mc_socket );
190
-	xfer_close ( &slam->mc_socket, rc );
191
-	xfer_nullify ( &slam->xfer );
192
-	xfer_close ( &slam->xfer, rc );
187
+	intf_shutdown ( &slam->socket, rc );
188
+	intf_shutdown ( &slam->mc_socket, rc );
189
+	intf_shutdown ( &slam->xfer, rc );
193 190
 }
194 191
 
195 192
 /****************************************************************************
@@ -473,15 +470,13 @@ static int slam_pull_header ( struct slam_request *slam,
473 470
 /**
474 471
  * Receive SLAM data packet
475 472
  *
476
- * @v mc_socket		SLAM multicast socket
473
+ * @v slam		SLAM request
477 474
  * @v iobuf		I/O buffer
478 475
  * @ret rc		Return status code
479 476
  */
480
-static int slam_mc_socket_deliver ( struct xfer_interface *mc_socket,
477
+static int slam_mc_socket_deliver ( struct slam_request *slam,
481 478
 				    struct io_buffer *iobuf,
482 479
 				    struct xfer_metadata *rx_meta __unused ) {
483
-	struct slam_request *slam =
484
-		container_of ( mc_socket, struct slam_request, mc_socket );
485 480
 	struct xfer_metadata meta;
486 481
 	unsigned long packet;
487 482
 	size_t len;
@@ -533,8 +528,7 @@ static int slam_mc_socket_deliver ( struct xfer_interface *mc_socket,
533 528
 	memset ( &meta, 0, sizeof ( meta ) );
534 529
 	meta.whence = SEEK_SET;
535 530
 	meta.offset = ( packet * slam->block_size );
536
-	if ( ( rc = xfer_deliver_iob_meta ( &slam->xfer, iobuf,
537
-					    &meta ) ) != 0 )
531
+	if ( ( rc = xfer_deliver ( &slam->xfer, iobuf, &meta ) ) != 0 )
538 532
 		goto err;
539 533
 
540 534
 	/* Mark block as received */
@@ -556,15 +550,13 @@ static int slam_mc_socket_deliver ( struct xfer_interface *mc_socket,
556 550
 /**
557 551
  * Receive SLAM non-data packet
558 552
  *
559
- * @v socket		SLAM unicast socket
553
+ * @v slam		SLAM request
560 554
  * @v iobuf		I/O buffer
561 555
  * @ret rc		Return status code
562 556
  */
563
-static int slam_socket_deliver ( struct xfer_interface *socket,
557
+static int slam_socket_deliver ( struct slam_request *slam,
564 558
 				 struct io_buffer *iobuf,
565 559
 				 struct xfer_metadata *rx_meta __unused ) {
566
-	struct slam_request *slam =
567
-		container_of ( socket, struct slam_request, socket );
568 560
 	int rc;
569 561
 
570 562
 	/* Restart the master client timer */
@@ -597,90 +589,41 @@ static int slam_socket_deliver ( struct xfer_interface *socket,
597 589
 
598 590
 }
599 591
 
600
-/**
601
- * Close SLAM unicast socket
602
- *
603
- * @v socket		SLAM unicast socket
604
- * @v rc		Reason for close
605
- */
606
-static void slam_socket_close ( struct xfer_interface *socket, int rc ) {
607
-	struct slam_request *slam =
608
-		container_of ( socket, struct slam_request, socket );
609
-
610
-	DBGC ( slam, "SLAM %p unicast socket closed: %s\n",
611
-	       slam, strerror ( rc ) );
612
-
613
-	slam_finished ( slam, rc );
614
-}
615
-
616
-/** SLAM unicast socket data transfer operations */
617
-static struct xfer_interface_operations slam_socket_operations = {
618
-	.close		= slam_socket_close,
619
-	.vredirect	= xfer_vreopen,
620
-	.window		= unlimited_xfer_window,
621
-	.alloc_iob	= default_xfer_alloc_iob,
622
-	.deliver_iob	= slam_socket_deliver,
623
-	.deliver_raw	= xfer_deliver_as_iob,
592
+/** SLAM unicast socket interface operations */
593
+static struct interface_operation slam_socket_operations[] = {
594
+	INTF_OP ( xfer_deliver, struct slam_request *, slam_socket_deliver ),
595
+	INTF_OP ( intf_close, struct slam_request *, slam_finished ),
624 596
 };
625 597
 
626
-/**
627
- * Close SLAM multicast socket
628
- *
629
- * @v mc_socket		SLAM multicast socket
630
- * @v rc		Reason for close
631
- */
632
-static void slam_mc_socket_close ( struct xfer_interface *mc_socket, int rc ){
633
-	struct slam_request *slam =
634
-		container_of ( mc_socket, struct slam_request, mc_socket );
635
-
636
-	DBGC ( slam, "SLAM %p multicast socket closed: %s\n",
637
-	       slam, strerror ( rc ) );
638
-
639
-	slam_finished ( slam, rc );
640
-}
598
+/** SLAM unicast socket interface descriptor */
599
+static struct interface_descriptor slam_socket_desc =
600
+	INTF_DESC ( struct slam_request, socket, slam_socket_operations );
641 601
 
642
-/** SLAM multicast socket data transfer operations */
643
-static struct xfer_interface_operations slam_mc_socket_operations = {
644
-	.close		= slam_mc_socket_close,
645
-	.vredirect	= xfer_vreopen,
646
-	.window		= unlimited_xfer_window,
647
-	.alloc_iob	= default_xfer_alloc_iob,
648
-	.deliver_iob	= slam_mc_socket_deliver,
649
-	.deliver_raw	= xfer_deliver_as_iob,
602
+/** SLAM multicast socket interface operations */
603
+static struct interface_operation slam_mc_socket_operations[] = {
604
+	INTF_OP ( xfer_deliver, struct slam_request *, slam_mc_socket_deliver ),
605
+	INTF_OP ( intf_close, struct slam_request *, slam_finished ),
650 606
 };
651 607
 
608
+/** SLAM multicast socket interface descriptor */
609
+static struct interface_descriptor slam_mc_socket_desc =
610
+	INTF_DESC ( struct slam_request, mc_socket, slam_mc_socket_operations );
611
+
652 612
 /****************************************************************************
653 613
  *
654 614
  * Data transfer interface
655 615
  *
656 616
  */
657 617
 
658
-/**
659
- * Close SLAM data transfer interface
660
- *
661
- * @v xfer		SLAM data transfer interface
662
- * @v rc		Reason for close
663
- */
664
-static void slam_xfer_close ( struct xfer_interface *xfer, int rc ) {
665
-	struct slam_request *slam =
666
-		container_of ( xfer, struct slam_request, xfer );
667
-
668
-	DBGC ( slam, "SLAM %p data transfer interface closed: %s\n",
669
-	       slam, strerror ( rc ) );
670
-
671
-	slam_finished ( slam, rc );
672
-}
673
-
674
-/** SLAM data transfer operations */
675
-static struct xfer_interface_operations slam_xfer_operations = {
676
-	.close		= slam_xfer_close,
677
-	.vredirect	= ignore_xfer_vredirect,
678
-	.window		= unlimited_xfer_window,
679
-	.alloc_iob	= default_xfer_alloc_iob,
680
-	.deliver_iob	= xfer_deliver_as_raw,
681
-	.deliver_raw	= ignore_xfer_deliver_raw,
618
+/** SLAM data transfer interface operations */
619
+static struct interface_operation slam_xfer_operations[] = {
620
+	INTF_OP ( intf_close, struct slam_request *, slam_finished ),
682 621
 };
683 622
 
623
+/** SLAM data transfer interface descriptor */
624
+static struct interface_descriptor slam_xfer_desc =
625
+	INTF_DESC ( struct slam_request, xfer, slam_xfer_operations );
626
+
684 627
 /**
685 628
  * Parse SLAM URI multicast address
686 629
  *
@@ -729,7 +672,7 @@ static int slam_parse_multicast_address ( struct slam_request *slam,
729 672
  * @v uri		Uniform Resource Identifier
730 673
  * @ret rc		Return status code
731 674
  */
732
-static int slam_open ( struct xfer_interface *xfer, struct uri *uri ) {
675
+static int slam_open ( struct interface *xfer, struct uri *uri ) {
733 676
 	static const struct sockaddr_in default_multicast = {
734 677
 		.sin_family = AF_INET,
735 678
 		.sin_port = htons ( SLAM_DEFAULT_MULTICAST_PORT ),
@@ -749,10 +692,9 @@ static int slam_open ( struct xfer_interface *xfer, struct uri *uri ) {
749 692
 	if ( ! slam )
750 693
 		return -ENOMEM;
751 694
 	ref_init ( &slam->refcnt, slam_free );
752
-	xfer_init ( &slam->xfer, &slam_xfer_operations, &slam->refcnt );
753
-	xfer_init ( &slam->socket, &slam_socket_operations, &slam->refcnt );
754
-	xfer_init ( &slam->mc_socket, &slam_mc_socket_operations,
755
-		    &slam->refcnt );
695
+	intf_init ( &slam->xfer, &slam_xfer_desc, &slam->refcnt );
696
+	intf_init ( &slam->socket, &slam_socket_desc, &slam->refcnt );
697
+	intf_init ( &slam->mc_socket, &slam_mc_socket_desc, &slam->refcnt );
756 698
 	timer_init ( &slam->master_timer, slam_master_timer_expired );
757 699
 	timer_init ( &slam->slave_timer, slam_slave_timer_expired );
758 700
 	/* Fake an invalid cached header of { 0x00, ... } */
@@ -795,7 +737,7 @@ static int slam_open ( struct xfer_interface *xfer, struct uri *uri ) {
795 737
 	start_timer_fixed ( &slam->slave_timer, SLAM_SLAVE_TIMEOUT );
796 738
 
797 739
 	/* Attach to parent interface, mortalise self, and return */
798
-	xfer_plug_plug ( &slam->xfer, xfer );
740
+	intf_plug_plug ( &slam->xfer, xfer );
799 741
 	ref_put ( &slam->refcnt );
800 742
 	return 0;
801 743
 

+ 46
- 88
src/net/udp/tftp.c Переглянути файл

@@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
27 27
 #include <errno.h>
28 28
 #include <assert.h>
29 29
 #include <ipxe/refcnt.h>
30
+#include <ipxe/iobuf.h>
30 31
 #include <ipxe/xfer.h>
31 32
 #include <ipxe/open.h>
32 33
 #include <ipxe/uri.h>
@@ -79,14 +80,14 @@ struct tftp_request {
79 80
 	/** Reference count */
80 81
 	struct refcnt refcnt;
81 82
 	/** Data transfer interface */
82
-	struct xfer_interface xfer;
83
+	struct interface xfer;
83 84
 
84 85
 	/** URI being fetched */
85 86
 	struct uri *uri;
86 87
 	/** Transport layer interface */
87
-	struct xfer_interface socket;
88
+	struct interface socket;
88 89
 	/** Multicast transport layer interface */
89
-	struct xfer_interface mc_socket;
90
+	struct interface mc_socket;
90 91
 
91 92
 	/** Data block size
92 93
 	 *
@@ -183,12 +184,9 @@ static void tftp_done ( struct tftp_request *tftp, int rc ) {
183 184
 	stop_timer ( &tftp->timer );
184 185
 
185 186
 	/* Close all data transfer interfaces */
186
-	xfer_nullify ( &tftp->socket );
187
-	xfer_close ( &tftp->socket, rc );
188
-	xfer_nullify ( &tftp->mc_socket );
189
-	xfer_close ( &tftp->mc_socket, rc );
190
-	xfer_nullify ( &tftp->xfer );
191
-	xfer_close ( &tftp->xfer, rc );
187
+	intf_shutdown ( &tftp->socket, rc );
188
+	intf_shutdown ( &tftp->mc_socket, rc );
189
+	intf_shutdown ( &tftp->xfer, rc );
192 190
 }
193 191
 
194 192
 /**
@@ -202,7 +200,7 @@ static int tftp_reopen ( struct tftp_request *tftp ) {
202 200
 	int rc;
203 201
 
204 202
 	/* Close socket */
205
-	xfer_close ( &tftp->socket, 0 );
203
+	intf_restart ( &tftp->socket, 0 );
206 204
 
207 205
 	/* Disable ACK sending. */
208 206
 	tftp->flags &= ~TFTP_FL_SEND_ACK;
@@ -236,7 +234,7 @@ static int tftp_reopen_mc ( struct tftp_request *tftp,
236 234
 	int rc;
237 235
 
238 236
 	/* Close multicast socket */
239
-	xfer_close ( &tftp->mc_socket, 0 );
237
+	intf_restart ( &tftp->mc_socket, 0 );
240 238
 
241 239
 	/* Open multicast socket.  We never send via this socket, so
242 240
 	 * use the local address as the peer address (since the peer
@@ -423,7 +421,7 @@ static int tftp_send_ack ( struct tftp_request *tftp ) {
423 421
 	ack->block = htons ( block );
424 422
 
425 423
 	/* ACK always goes to the peer recorded from the RRQ response */
426
-	return xfer_deliver_iob_meta ( &tftp->socket, iobuf, &meta );
424
+	return xfer_deliver ( &tftp->socket, iobuf, &meta );
427 425
 }
428 426
 
429 427
 /**
@@ -459,7 +457,7 @@ static int tftp_send_error ( struct tftp_request *tftp, int errcode,
459 457
 	strcpy ( err->errmsg, errmsg );
460 458
 
461 459
 	/* ERR always goes to the peer recorded from the RRQ response */
462
-	return xfer_deliver_iob_meta ( &tftp->socket, iobuf, &meta );
460
+	return xfer_deliver ( &tftp->socket, iobuf, &meta );
463 461
 }
464 462
 
465 463
 /**
@@ -525,7 +523,7 @@ static void tftp_timer_expired ( struct retry_timer *timer, int fail ) {
525 523
 				tftp->flags = TFTP_FL_RRQ_SIZES;
526 524
 
527 525
 				/* Close multicast socket */
528
-				xfer_close ( &tftp->mc_socket, 0 );
526
+				intf_restart ( &tftp->mc_socket, 0 );
529 527
 
530 528
 				/* Reset retry timer */
531 529
 				start_timer_nodelay ( &tftp->timer );
@@ -858,8 +856,8 @@ static int tftp_rx_data ( struct tftp_request *tftp,
858 856
 	memset ( &meta, 0, sizeof ( meta ) );
859 857
 	meta.whence = SEEK_SET;
860 858
 	meta.offset = offset;
861
-	if ( ( rc = xfer_deliver_iob_meta ( &tftp->xfer, iob_disown ( iobuf ),
862
-					    &meta ) ) != 0 ) {
859
+	if ( ( rc = xfer_deliver ( &tftp->xfer, iob_disown ( iobuf ),
860
+				   &meta ) ) != 0 ) {
863 861
 		DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
864 862
 		       tftp, strerror ( rc ) );
865 863
 		goto done;
@@ -998,16 +996,14 @@ static int tftp_rx ( struct tftp_request *tftp,
998 996
 /**
999 997
  * Receive new data via socket
1000 998
  *
1001
- * @v socket		Transport layer interface
999
+ * @v tftp		TFTP connection
1002 1000
  * @v iobuf		I/O buffer
1003 1001
  * @v meta		Transfer metadata
1004 1002
  * @ret rc		Return status code
1005 1003
  */
1006
-static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
1007
-				     struct io_buffer *iobuf,
1008
-				     struct xfer_metadata *meta ) {
1009
-	struct tftp_request *tftp =
1010
-		container_of ( socket, struct tftp_request, socket );
1004
+static int tftp_socket_deliver ( struct tftp_request *tftp,
1005
+				 struct io_buffer *iobuf,
1006
+				 struct xfer_metadata *meta ) {
1011 1007
 
1012 1008
 	/* Enable sending ACKs when we receive a unicast packet.  This
1013 1009
 	 * covers three cases:
@@ -1030,67 +1026,30 @@ static int tftp_socket_deliver_iob ( struct xfer_interface *socket,
1030 1026
 }
1031 1027
 
1032 1028
 /** TFTP socket operations */
1033
-static struct xfer_interface_operations tftp_socket_operations = {
1034
-	.close		= ignore_xfer_close,
1035
-	.vredirect	= xfer_vreopen,
1036
-	.window		= unlimited_xfer_window,
1037
-	.alloc_iob	= default_xfer_alloc_iob,
1038
-	.deliver_iob	= tftp_socket_deliver_iob,
1039
-	.deliver_raw	= xfer_deliver_as_iob,
1029
+static struct interface_operation tftp_socket_operations[] = {
1030
+	INTF_OP ( xfer_deliver, struct tftp_request *, tftp_socket_deliver ),
1040 1031
 };
1041 1032
 
1042
-/**
1043
- * Receive new data via multicast socket
1044
- *
1045
- * @v mc_socket		Multicast transport layer interface
1046
- * @v iobuf		I/O buffer
1047
- * @v meta		Transfer metadata
1048
- * @ret rc		Return status code
1049
- */
1050
-static int tftp_mc_socket_deliver_iob ( struct xfer_interface *mc_socket,
1051
-					struct io_buffer *iobuf,
1052
-					struct xfer_metadata *meta ) {
1053
-	struct tftp_request *tftp =
1054
-		container_of ( mc_socket, struct tftp_request, mc_socket );
1055
-
1056
-	return tftp_rx ( tftp, iobuf, meta );
1057
-}
1033
+/** TFTP socket interface descriptor */
1034
+static struct interface_descriptor tftp_socket_desc =
1035
+	INTF_DESC ( struct tftp_request, socket, tftp_socket_operations );
1058 1036
 
1059 1037
 /** TFTP multicast socket operations */
1060
-static struct xfer_interface_operations tftp_mc_socket_operations = {
1061
-	.close		= ignore_xfer_close,
1062
-	.vredirect	= xfer_vreopen,
1063
-	.window		= unlimited_xfer_window,
1064
-	.alloc_iob	= default_xfer_alloc_iob,
1065
-	.deliver_iob	= tftp_mc_socket_deliver_iob,
1066
-	.deliver_raw	= xfer_deliver_as_iob,
1038
+static struct interface_operation tftp_mc_socket_operations[] = {
1039
+	INTF_OP ( xfer_deliver, struct tftp_request *, tftp_rx ),
1067 1040
 };
1068 1041
 
1069
-/**
1070
- * Close TFTP data transfer interface
1071
- *
1072
- * @v xfer		Data transfer interface
1073
- * @v rc		Reason for close
1074
- */
1075
-static void tftp_xfer_close ( struct xfer_interface *xfer, int rc ) {
1076
-	struct tftp_request *tftp =
1077
-		container_of ( xfer, struct tftp_request, xfer );
1078
-
1079
-	DBGC ( tftp, "TFTP %p interface closed: %s\n",
1080
-	       tftp, strerror ( rc ) );
1081
-
1082
-	tftp_done ( tftp, rc );
1083
-}
1042
+/** TFTP multicast socket interface descriptor */
1043
+static struct interface_descriptor tftp_mc_socket_desc =
1044
+	INTF_DESC ( struct tftp_request, mc_socket, tftp_mc_socket_operations );
1084 1045
 
1085 1046
 /**
1086 1047
  * Check flow control window
1087 1048
  *
1088
- * @v xfer		Data transfer interface
1049
+ * @v tftp		TFTP connection
1089 1050
  * @ret len		Length of window
1090 1051
  */
1091
-static size_t tftp_xfer_window ( struct xfer_interface *xfer ) {
1092
-	struct tftp_request *tftp =
1093
-		container_of ( xfer, struct tftp_request, xfer );
1052
+static size_t tftp_xfer_window ( struct tftp_request *tftp ) {
1094 1053
 
1095 1054
 	/* We abuse this data-xfer method to convey the blocksize to
1096 1055
 	 * the caller.  This really should be done using some kind of
@@ -1101,15 +1060,15 @@ static size_t tftp_xfer_window ( struct xfer_interface *xfer ) {
1101 1060
 }
1102 1061
 
1103 1062
 /** TFTP data transfer interface operations */
1104
-static struct xfer_interface_operations tftp_xfer_operations = {
1105
-	.close		= tftp_xfer_close,
1106
-	.vredirect	= ignore_xfer_vredirect,
1107
-	.window		= tftp_xfer_window,
1108
-	.alloc_iob	= default_xfer_alloc_iob,
1109
-	.deliver_iob	= xfer_deliver_as_raw,
1110
-	.deliver_raw	= ignore_xfer_deliver_raw,
1063
+static struct interface_operation tftp_xfer_operations[] = {
1064
+	INTF_OP ( xfer_window, struct tftp_request *, tftp_xfer_window ),
1065
+	INTF_OP ( intf_close, struct tftp_request *, tftp_done ),
1111 1066
 };
1112 1067
 
1068
+/** TFTP data transfer interface descriptor */
1069
+static struct interface_descriptor tftp_xfer_desc =
1070
+	INTF_DESC ( struct tftp_request, xfer, tftp_xfer_operations );
1071
+
1113 1072
 /**
1114 1073
  * Initiate TFTP/TFTM/MTFTP download
1115 1074
  *
@@ -1117,7 +1076,7 @@ static struct xfer_interface_operations tftp_xfer_operations = {
1117 1076
  * @v uri		Uniform Resource Identifier
1118 1077
  * @ret rc		Return status code
1119 1078
  */
1120
-static int tftp_core_open ( struct xfer_interface *xfer, struct uri *uri,
1079
+static int tftp_core_open ( struct interface *xfer, struct uri *uri,
1121 1080
 			    unsigned int default_port,
1122 1081
 			    struct sockaddr *multicast,
1123 1082
 			    unsigned int flags ) {
@@ -1135,10 +1094,9 @@ static int tftp_core_open ( struct xfer_interface *xfer, struct uri *uri,
1135 1094
 	if ( ! tftp )
1136 1095
 		return -ENOMEM;
1137 1096
 	ref_init ( &tftp->refcnt, tftp_free );
1138
-	xfer_init ( &tftp->xfer, &tftp_xfer_operations, &tftp->refcnt );
1139
-	xfer_init ( &tftp->socket, &tftp_socket_operations, &tftp->refcnt );
1140
-	xfer_init ( &tftp->mc_socket, &tftp_mc_socket_operations,
1141
-		    &tftp->refcnt );
1097
+	intf_init ( &tftp->xfer, &tftp_xfer_desc, &tftp->refcnt );
1098
+	intf_init ( &tftp->socket, &tftp_socket_desc, &tftp->refcnt );
1099
+	intf_init ( &tftp->mc_socket, &tftp_mc_socket_desc, &tftp->refcnt );
1142 1100
 	timer_init ( &tftp->timer, tftp_timer_expired );
1143 1101
 	tftp->uri = uri_get ( uri );
1144 1102
 	tftp->blksize = TFTP_DEFAULT_BLKSIZE;
@@ -1159,7 +1117,7 @@ static int tftp_core_open ( struct xfer_interface *xfer, struct uri *uri,
1159 1117
 	start_timer_nodelay ( &tftp->timer );
1160 1118
 
1161 1119
 	/* Attach to parent interface, mortalise self, and return */
1162
-	xfer_plug_plug ( &tftp->xfer, xfer );
1120
+	intf_plug_plug ( &tftp->xfer, xfer );
1163 1121
 	ref_put ( &tftp->refcnt );
1164 1122
 	return 0;
1165 1123
 
@@ -1178,7 +1136,7 @@ static int tftp_core_open ( struct xfer_interface *xfer, struct uri *uri,
1178 1136
  * @v uri		Uniform Resource Identifier
1179 1137
  * @ret rc		Return status code
1180 1138
  */
1181
-static int tftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
1139
+static int tftp_open ( struct interface *xfer, struct uri *uri ) {
1182 1140
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1183 1141
 				TFTP_FL_RRQ_SIZES );
1184 1142
 
@@ -1197,7 +1155,7 @@ struct uri_opener tftp_uri_opener __uri_opener = {
1197 1155
  * @v uri		Uniform Resource Identifier
1198 1156
  * @ret rc		Return status code
1199 1157
  */
1200
-static int tftpsize_open ( struct xfer_interface *xfer, struct uri *uri ) {
1158
+static int tftpsize_open ( struct interface *xfer, struct uri *uri ) {
1201 1159
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1202 1160
 				( TFTP_FL_RRQ_SIZES |
1203 1161
 				  TFTP_FL_SIZEONLY ) );
@@ -1217,7 +1175,7 @@ struct uri_opener tftpsize_uri_opener __uri_opener = {
1217 1175
  * @v uri		Uniform Resource Identifier
1218 1176
  * @ret rc		Return status code
1219 1177
  */
1220
-static int tftm_open ( struct xfer_interface *xfer, struct uri *uri ) {
1178
+static int tftm_open ( struct interface *xfer, struct uri *uri ) {
1221 1179
 	return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1222 1180
 				( TFTP_FL_RRQ_SIZES |
1223 1181
 				  TFTP_FL_RRQ_MULTICAST ) );
@@ -1237,7 +1195,7 @@ struct uri_opener tftm_uri_opener __uri_opener = {
1237 1195
  * @v uri		Uniform Resource Identifier
1238 1196
  * @ret rc		Return status code
1239 1197
  */
1240
-static int mtftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
1198
+static int mtftp_open ( struct interface *xfer, struct uri *uri ) {
1241 1199
 	return tftp_core_open ( xfer, uri, MTFTP_PORT,
1242 1200
 				( struct sockaddr * ) &tftp_mtftp_socket,
1243 1201
 				TFTP_FL_MTFTP_RECOVERY );

Завантаження…
Відмінити
Зберегти