浏览代码

[interface] Convert all name-resolution interfaces to generic interfaces

Remove name-resolution as an interface type, and replace
name-resolution interfaces with generic interfaces supporting the
resolv_done() method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 16 年前
父节点
当前提交
7b4fbd93a5
共有 4 个文件被更改,包括 169 次插入260 次删除
  1. 33
    32
      src/arch/i386/interface/syslinux/comboot_resolv.c
  2. 112
    97
      src/core/resolv.c
  3. 6
    125
      src/include/ipxe/resolv.h
  4. 18
    6
      src/net/udp/dns.c

+ 33
- 32
src/arch/i386/interface/syslinux/comboot_resolv.c 查看文件

@@ -7,54 +7,55 @@
7 7
 
8 8
 FILE_LICENCE ( GPL2_OR_LATER );
9 9
 
10
-static int comboot_resolv_rc;
11
-static struct in_addr comboot_resolv_addr;
12
-
13
-static void comboot_resolv_done ( struct resolv_interface *resolv,
14
-				  struct sockaddr *sa, int rc ) {
15
-	struct sockaddr_in *sin;
10
+struct comboot_resolver {
11
+	struct interface intf;
12
+	int rc;
13
+	struct in_addr addr;
14
+};
16 15
 
17
-	resolv_unplug ( resolv );
16
+static void comboot_resolv_close ( struct comboot_resolver *comboot_resolver,
17
+				   int rc ) {
18
+	comboot_resolver->rc = rc;
19
+	intf_shutdown ( &comboot_resolver->intf, rc );
20
+}
18 21
 
19
-	if ( rc != 0 ) {
20
-		comboot_resolv_rc = rc;
21
-		return;
22
-	}
22
+static void comboot_resolv_done ( struct comboot_resolver *comboot_resolver,
23
+				  struct sockaddr *sa ) {
24
+	struct sockaddr_in *sin;
23 25
 
24
-	if ( sa->sa_family != AF_INET ) {
25
-		comboot_resolv_rc = -EAFNOSUPPORT;
26
-		return;
26
+	if ( sa->sa_family == AF_INET ) {
27
+		sin = ( ( struct sockaddr_in * ) sa );
28
+		comboot_resolver->addr = sin->sin_addr;
27 29
 	}
28
-
29
-	sin = ( ( struct sockaddr_in * ) sa );
30
-	comboot_resolv_addr = sin->sin_addr;
31
-
32
-	comboot_resolv_rc = 0;
33 30
 }
34 31
 
35
-static struct resolv_interface_operations comboot_resolv_ops = {
36
-	.done = comboot_resolv_done,
32
+static struct interface_operation comboot_resolv_op[] = {
33
+	INTF_OP ( intf_close, struct comboot_resolver *, comboot_resolv_close ),
34
+	INTF_OP ( resolv_done, struct comboot_resolver *, comboot_resolv_done ),
37 35
 };
38 36
 
39
-static struct resolv_interface comboot_resolver = {
40
-	.intf = {
41
-		.dest = &null_resolv.intf,
42
-		.refcnt = NULL,
43
-	},
44
-	.op = &comboot_resolv_ops,
37
+static struct interface_descriptor comboot_resolv_desc =
38
+	INTF_DESC ( struct comboot_resolver, intf, comboot_resolv_op );
39
+
40
+static struct comboot_resolver comboot_resolver = {
41
+	.intf = INTF_INIT ( comboot_resolv_desc ),
45 42
 };
46 43
 
47 44
 int comboot_resolv ( const char *name, struct in_addr *address ) {
48 45
 	int rc;
49 46
 
50
-	comboot_resolv_rc = -EINPROGRESS;
47
+	comboot_resolver.rc = -EINPROGRESS;
48
+	comboot_resolver.addr.s_addr = 0;
51 49
 
52
-	if ( ( rc = resolv ( &comboot_resolver, name, NULL ) ) != 0 )
50
+	if ( ( rc = resolv ( &comboot_resolver.intf, name, NULL ) ) != 0 )
53 51
 		return rc;
54 52
 
55
-	while ( comboot_resolv_rc == -EINPROGRESS )
53
+	while ( comboot_resolver.rc == -EINPROGRESS )
56 54
 		step();
57 55
 
58
-	*address = comboot_resolv_addr;
59
-	return comboot_resolv_rc;
56
+	if ( ! comboot_resolver.addr.s_addr )
57
+		return -EAFNOSUPPORT;
58
+
59
+	*address = comboot_resolver.addr;
60
+	return comboot_resolver.rc;
60 61
 }

+ 112
- 97
src/core/resolv.c 查看文件

@@ -42,47 +42,29 @@ FILE_LICENCE ( GPL2_OR_LATER );
42 42
  */
43 43
 
44 44
 /**
45
- * Name resolution completed
45
+ * Name resolved
46 46
  *
47
- * @v resolv		Name resolution interface
47
+ * @v intf		Object interface
48 48
  * @v sa		Completed socket address (if successful)
49
- * @v rc		Final status code
50 49
  */
51
-void resolv_done ( struct resolv_interface *resolv, struct sockaddr *sa,
52
-		   int rc ) {
53
-	struct resolv_interface *dest = resolv_get_dest ( resolv );
54
-
55
-	resolv_unplug ( resolv );
56
-	dest->op->done ( dest, sa, rc );
57
-	resolv_put ( dest );
58
-}
50
+void resolv_done ( struct interface *intf, struct sockaddr *sa ) {
51
+	struct interface *dest;
52
+	resolv_done_TYPE ( void * ) *op =
53
+		intf_get_dest_op ( intf, resolv_done, &dest );
54
+	void *object = intf_object ( dest );
55
+
56
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " resolv_done\n",
57
+	       INTF_INTF_DBG ( intf, dest ) );
58
+
59
+	if ( op ) {
60
+		op ( object, sa );
61
+	} else {
62
+		/* Default is to ignore resolutions */
63
+	}
59 64
 
60
-/**
61
- * Ignore name resolution done() event
62
- *
63
- * @v resolv		Name resolution interface
64
- * @v sa		Completed socket address (if successful)
65
- * @v rc		Final status code
66
- */
67
-void ignore_resolv_done ( struct resolv_interface *resolv __unused,
68
-			  struct sockaddr *sa __unused, int rc __unused ) {
69
-	/* Do nothing */
65
+	intf_put ( dest );
70 66
 }
71 67
 
72
-/** Null name resolution interface operations */
73
-struct resolv_interface_operations null_resolv_ops = {
74
-	.done		= ignore_resolv_done,
75
-};
76
-
77
-/** Null name resolution interface */
78
-struct resolv_interface null_resolv = {
79
-	.intf = {
80
-		.dest = &null_resolv.intf,
81
-		.refcnt = NULL,
82
-	},
83
-	.op = &null_resolv_ops,
84
-};
85
-
86 68
 /***************************************************************************
87 69
  *
88 70
  * Numeric name resolver
@@ -95,7 +77,7 @@ struct numeric_resolv {
95 77
 	/** Reference counter */
96 78
 	struct refcnt refcnt;
97 79
 	/** Name resolution interface */
98
-	struct resolv_interface resolv;
80
+	struct interface resolv;
99 81
 	/** Process */
100 82
 	struct process process;
101 83
 	/** Completed socket address */
@@ -107,12 +89,14 @@ struct numeric_resolv {
107 89
 static void numeric_step ( struct process *process ) {
108 90
 	struct numeric_resolv *numeric =
109 91
 		container_of ( process, struct numeric_resolv, process );
110
-	
111
-	resolv_done ( &numeric->resolv, &numeric->sa, numeric->rc );
92
+
112 93
 	process_del ( process );
94
+	if ( numeric->rc == 0 )
95
+		resolv_done ( &numeric->resolv, &numeric->sa );
96
+	intf_shutdown ( &numeric->resolv, numeric->rc );
113 97
 }
114 98
 
115
-static int numeric_resolv ( struct resolv_interface *resolv,
99
+static int numeric_resolv ( struct interface *resolv,
116 100
 			    const char *name, struct sockaddr *sa ) {
117 101
 	struct numeric_resolv *numeric;
118 102
 	struct sockaddr_in *sin;
@@ -122,7 +106,7 @@ static int numeric_resolv ( struct resolv_interface *resolv,
122 106
 	if ( ! numeric )
123 107
 		return -ENOMEM;
124 108
 	ref_init ( &numeric->refcnt, NULL );
125
-	resolv_init ( &numeric->resolv, &null_resolv_ops, &numeric->refcnt );
109
+	intf_init ( &numeric->resolv, &null_intf_desc, &numeric->refcnt );
126 110
 	process_init ( &numeric->process, numeric_step, &numeric->refcnt );
127 111
 	memcpy ( &numeric->sa, sa, sizeof ( numeric->sa ) );
128 112
 
@@ -131,12 +115,14 @@ static int numeric_resolv ( struct resolv_interface *resolv,
131 115
 
132 116
 	/* Attempt to resolve name */
133 117
 	sin = ( ( struct sockaddr_in * ) &numeric->sa );
134
-	sin->sin_family = AF_INET;
135
-	if ( inet_aton ( name, &sin->sin_addr ) == 0 )
118
+	if ( inet_aton ( name, &sin->sin_addr ) != 0 ) {
119
+		sin->sin_family = AF_INET;
120
+	} else {
136 121
 		numeric->rc = -EINVAL;
122
+	}
137 123
 
138 124
 	/* Attach to parent interface, mortalise self, and return */
139
-	resolv_plug_plug ( &numeric->resolv, resolv );
125
+	intf_plug_plug ( &numeric->resolv, resolv );
140 126
 	ref_put ( &numeric->refcnt );
141 127
 	return 0;
142 128
 }
@@ -158,10 +144,10 @@ struct resolv_mux {
158 144
 	/** Reference counter */
159 145
 	struct refcnt refcnt;
160 146
 	/** Parent name resolution interface */
161
-	struct resolv_interface parent;
147
+	struct interface parent;
162 148
 
163 149
 	/** Child name resolution interface */
164
-	struct resolv_interface child;
150
+	struct interface child;
165 151
 	/** Current child resolver */
166 152
 	struct resolver *resolver;
167 153
 
@@ -180,7 +166,7 @@ struct resolv_mux {
180 166
  * @v mux		Name resolution multiplexer
181 167
  * @ret rc		Return status code
182 168
  */
183
-static int resolv_mux_try ( struct resolv_mux *mux ) {
169
+static int resmux_try ( struct resolv_mux *mux ) {
184 170
 	struct resolver *resolver = mux->resolver;
185 171
 	int rc;
186 172
 
@@ -197,19 +183,31 @@ static int resolv_mux_try ( struct resolv_mux *mux ) {
197 183
 }
198 184
 
199 185
 /**
200
- * Handle done() event from child name resolver
186
+ * Child resolved name
201 187
  *
202
- * @v resolv		Child name resolution interface
203
- * @v sa		Completed socket address (if successful)
204
- * @v rc		Final status code
188
+ * @v mux		Name resolution multiplexer
189
+ * @v sa		Completed socket address
205 190
  */
206
-static void resolv_mux_done ( struct resolv_interface *resolv,
207
-			      struct sockaddr *sa, int rc ) {
208
-	struct resolv_mux *mux =
209
-		container_of ( resolv, struct resolv_mux, child );
191
+static void resmux_child_resolv_done ( struct resolv_mux *mux,
192
+				       struct sockaddr *sa ) {
210 193
 
211
-	/* Unplug child */
212
-	resolv_unplug ( &mux->child );
194
+	DBGC ( mux, "RESOLV %p resolved \"%s\" using method %s\n",
195
+	       mux, mux->name, mux->resolver->name );
196
+
197
+	/* Pass resolution to parent */
198
+	resolv_done ( &mux->parent, sa );
199
+}
200
+
201
+/**
202
+ * Child finished resolution
203
+ *
204
+ * @v mux		Name resolution multiplexer
205
+ * @v rc		Return status code
206
+ */
207
+static void resmux_child_close ( struct resolv_mux *mux, int rc ) {
208
+
209
+	/* Restart child interface */
210
+	intf_restart ( &mux->child, rc );
213 211
 
214 212
 	/* If this resolution succeeded, stop now */
215 213
 	if ( rc == 0 ) {
@@ -224,21 +222,26 @@ static void resolv_mux_done ( struct resolv_interface *resolv,
224 222
 		DBGC ( mux, "RESOLV %p failed to resolve name\n", mux );
225 223
 		goto finished;
226 224
 	}
227
-	if ( ( rc = resolv_mux_try ( mux ) ) != 0 )
225
+	if ( ( rc = resmux_try ( mux ) ) != 0 )
228 226
 		goto finished;
229 227
 
230 228
 	/* Next resolver is now running */
231 229
 	return;
232
-	
230
+
233 231
  finished:
234
-	resolv_done ( &mux->parent, sa, rc );
232
+	intf_shutdown ( &mux->parent, rc );
235 233
 }
236 234
 
237
-/** Name resolution multiplexer operations */
238
-static struct resolv_interface_operations resolv_mux_child_ops = {
239
-	.done		= resolv_mux_done,
235
+/** Name resolution multiplexer child interface operations */
236
+static struct interface_operation resmux_child_op[] = {
237
+	INTF_OP ( resolv_done, struct resolv_mux *, resmux_child_resolv_done ),
238
+	INTF_OP ( intf_close, struct resolv_mux *, resmux_child_close ),
240 239
 };
241 240
 
241
+/** Name resolution multiplexer child interface descriptor */
242
+static struct interface_descriptor resmux_child_desc =
243
+	INTF_DESC ( struct resolv_mux, child, resmux_child_op );
244
+
242 245
 /**
243 246
  * Start name resolution
244 247
  *
@@ -247,7 +250,7 @@ static struct resolv_interface_operations resolv_mux_child_ops = {
247 250
  * @v sa		Socket address to complete
248 251
  * @ret rc		Return status code
249 252
  */
250
-int resolv ( struct resolv_interface *resolv, const char *name,
253
+int resolv ( struct interface *resolv, const char *name,
251 254
 	     struct sockaddr *sa ) {
252 255
 	struct resolv_mux *mux;
253 256
 	size_t name_len = ( strlen ( name ) + 1 );
@@ -258,10 +261,11 @@ int resolv ( struct resolv_interface *resolv, const char *name,
258 261
 	if ( ! mux )
259 262
 		return -ENOMEM;
260 263
 	ref_init ( &mux->refcnt, NULL );
261
-	resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
262
-	resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
264
+	intf_init ( &mux->parent, &null_intf_desc, &mux->refcnt );
265
+	intf_init ( &mux->child, &resmux_child_desc, &mux->refcnt );
263 266
 	mux->resolver = table_start ( RESOLVERS );
264
-	memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
267
+	if ( sa )
268
+		memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
265 269
 	memcpy ( mux->name, name, name_len );
266 270
 
267 271
 	DBGC ( mux, "RESOLV %p attempting to resolve \"%s\"\n", mux, name );
@@ -270,11 +274,11 @@ int resolv ( struct resolv_interface *resolv, const char *name,
270 274
 	 * least one resolver (the numeric resolver), so no need to
271 275
 	 * check for the zero-resolvers-available case.
272 276
 	 */
273
-	if ( ( rc = resolv_mux_try ( mux ) ) != 0 )
277
+	if ( ( rc = resmux_try ( mux ) ) != 0 )
274 278
 		goto err;
275 279
 
276 280
 	/* Attach parent interface, mortalise self, and return */
277
-	resolv_plug_plug ( &mux->parent, resolv );
281
+	intf_plug_plug ( &mux->parent, resolv );
278 282
 	ref_put ( &mux->refcnt );
279 283
 	return 0;
280 284
 
@@ -297,7 +301,7 @@ struct named_socket {
297 301
 	/** Data transfer interface */
298 302
 	struct xfer_interface xfer;
299 303
 	/** Name resolution interface */
300
-	struct resolv_interface resolv;
304
+	struct interface resolv;
301 305
 	/** Communication semantics (e.g. SOCK_STREAM) */
302 306
 	int semantics;
303 307
 	/** Stored local socket address, if applicable */
@@ -307,15 +311,14 @@ struct named_socket {
307 311
 };
308 312
 
309 313
 /**
310
- * Finish using named socket
314
+ * Terminate named socket opener
311 315
  *
312 316
  * @v named		Named socket
313
- * @v rc		Reason for finish
317
+ * @v rc		Reason for termination
314 318
  */
315
-static void named_done ( struct named_socket *named, int rc ) {
316
-
317
-	/* Close all interfaces */
318
-	resolv_nullify ( &named->resolv );
319
+static void named_close ( struct named_socket *named, int rc ) {
320
+	/* Shut down interfaces */
321
+	intf_shutdown ( &named->resolv, rc );
319 322
 	xfer_nullify ( &named->xfer );
320 323
 	xfer_close ( &named->xfer, rc );
321 324
 }
@@ -330,7 +333,7 @@ static void named_xfer_close ( struct xfer_interface *xfer, int rc ) {
330 333
 	struct named_socket *named =
331 334
 		container_of ( xfer, struct named_socket, xfer );
332 335
 
333
-	named_done ( named, rc );
336
+	named_close ( named, rc );
334 337
 }
335 338
 
336 339
 /** Named socket opener data transfer interface operations */
@@ -344,34 +347,46 @@ static struct xfer_interface_operations named_xfer_ops = {
344 347
 };
345 348
 
346 349
 /**
347
- * Handle done() event
350
+ * Name resolved
348 351
  *
349
- * @v resolv		Name resolution interface
350
- * @v sa		Completed socket address (if successful)
351
- * @v rc		Final status code
352
+ * @v named		Named socket
353
+ * @v sa		Completed socket address
352 354
  */
353
-static void named_resolv_done ( struct resolv_interface *resolv,
354
-				struct sockaddr *sa, int rc ) {
355
-	struct named_socket *named =
356
-		container_of ( resolv, struct named_socket, resolv );
355
+static void named_resolv_done ( struct named_socket *named,
356
+				struct sockaddr *sa ) {
357
+	int rc;
357 358
 
358
-	/* Redirect if name resolution was successful */
359
-	if ( rc == 0 ) {
360
-		rc = xfer_redirect ( &named->xfer, LOCATION_SOCKET,
361
-				     named->semantics, sa,
362
-				     ( named->have_local ?
363
-				       &named->local : NULL ) );
359
+	/* Nullify data transfer interface */
360
+	xfer_nullify ( &named->xfer );
361
+
362
+	/* Redirect data-xfer interface */
363
+	if ( ( rc = xfer_redirect ( &named->xfer, LOCATION_SOCKET,
364
+				    named->semantics, sa,
365
+				    ( named->have_local ?
366
+				      &named->local : NULL ) ) ) != 0 ) {
367
+		/* Redirection failed - do not unplug data-xfer interface */
368
+		DBGC ( named, "NAMED %p could not redirect: %s\n",
369
+		       named, strerror ( rc ) );
370
+	} else {
371
+		/* Redirection succeeded - unplug data-xfer interface */
372
+		DBGC ( named, "NAMED %p redirected successfully\n", named );
373
+		xfer_unplug ( &named->xfer );
364 374
 	}
365 375
 
366
-	/* Terminate resolution */
367
-	named_done ( named, rc );
376
+	/* Terminate named socket opener */
377
+	named_close ( named, rc );
368 378
 }
369 379
 
370
-/** Named socket opener name resolution interface operations */
371
-static struct resolv_interface_operations named_resolv_ops = {
372
-	.done		= named_resolv_done,
380
+/** Named socket opener resolver interface operations */
381
+static struct interface_operation named_resolv_op[] = {
382
+	INTF_OP ( intf_close, struct named_socket *, named_close ),
383
+	INTF_OP ( resolv_done, struct named_socket *, named_resolv_done ),
373 384
 };
374 385
 
386
+/** Named socket opener resolver interface descriptor */
387
+static struct interface_descriptor named_resolv_desc =
388
+	INTF_DESC ( struct named_socket, resolv, named_resolv_op );
389
+
375 390
 /**
376 391
  * Open named socket
377 392
  *
@@ -393,14 +408,14 @@ int xfer_open_named_socket ( struct xfer_interface *xfer, int semantics,
393 408
 		return -ENOMEM;
394 409
 	ref_init ( &named->refcnt, NULL );
395 410
 	xfer_init ( &named->xfer, &named_xfer_ops, &named->refcnt );
396
-	resolv_init ( &named->resolv, &named_resolv_ops, &named->refcnt );
411
+	intf_init ( &named->resolv, &named_resolv_desc, &named->refcnt );
397 412
 	named->semantics = semantics;
398 413
 	if ( local ) {
399 414
 		memcpy ( &named->local, local, sizeof ( named->local ) );
400 415
 		named->have_local = 1;
401 416
 	}
402 417
 
403
-	DBGC ( named, "RESOLV %p opening named socket \"%s\"\n",
418
+	DBGC ( named, "NAMED %p opening \"%s\"\n",
404 419
 	       named, name );
405 420
 
406 421
 	/* Start name resolution */

+ 6
- 125
src/include/ipxe/resolv.h 查看文件

@@ -9,126 +9,10 @@
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12
-#include <ipxe/refcnt.h>
13 12
 #include <ipxe/interface.h>
14 13
 #include <ipxe/tables.h>
15
-#include <ipxe/socket.h>
16 14
 
17
-struct resolv_interface;
18
-
19
-/** Name resolution interface operations */
20
-struct resolv_interface_operations {
21
-	/** Name resolution completed
22
-	 *
23
-	 * @v resolv		Name resolution interface
24
-	 * @v sa		Completed socket address (if successful)
25
-	 * @v rc		Final status code
26
-	 */
27
-	void ( * done ) ( struct resolv_interface *resolv,
28
-			  struct sockaddr *sa, int rc );
29
-};
30
-
31
-/** A name resolution interface */
32
-struct resolv_interface {
33
-	/** Generic object communication interface */
34
-	struct interface intf;
35
-	/** Operations for received messages */
36
-	struct resolv_interface_operations *op;
37
-};
38
-
39
-extern struct resolv_interface null_resolv;
40
-extern struct resolv_interface_operations null_resolv_ops;
41
-
42
-/**
43
- * Initialise a name resolution interface
44
- *
45
- * @v resolv		Name resolution interface
46
- * @v op		Name resolution interface operations
47
- * @v refcnt		Containing object reference counter, or NULL
48
- */
49
-static inline void resolv_init ( struct resolv_interface *resolv,
50
-				 struct resolv_interface_operations *op,
51
-				 struct refcnt *refcnt ) {
52
-	resolv->intf.dest = &null_resolv.intf;
53
-	resolv->intf.refcnt = refcnt;
54
-	resolv->op = op;
55
-}
56
-
57
-/**
58
- * Get name resolution interface from generic object communication interface
59
- *
60
- * @v intf		Generic object communication interface
61
- * @ret resolv		Name resolution interface
62
- */
63
-static inline __attribute__ (( always_inline )) struct resolv_interface *
64
-intf_to_resolv ( struct interface *intf ) {
65
-	return container_of ( intf, struct resolv_interface, intf );
66
-}
67
-
68
-/**
69
- * Get reference to destination name resolution interface
70
- *
71
- * @v resolv		Name resolution interface
72
- * @ret dest		Destination interface
73
- */
74
-static inline __attribute__ (( always_inline )) struct resolv_interface *
75
-resolv_get_dest ( struct resolv_interface *resolv ) {
76
-	return intf_to_resolv ( intf_get ( resolv->intf.dest ) );
77
-}
78
-
79
-/**
80
- * Drop reference to name resolution interface
81
- *
82
- * @v resolv		name resolution interface
83
- */
84
-static inline __attribute__ (( always_inline )) void
85
-resolv_put ( struct resolv_interface *resolv ) {
86
-	intf_put ( &resolv->intf );
87
-}
88
-
89
-/**
90
- * Plug a name resolution interface into a new destination interface
91
- *
92
- * @v resolv		Name resolution interface
93
- * @v dest		New destination interface
94
- */
95
-static inline __attribute__ (( always_inline )) void
96
-resolv_plug ( struct resolv_interface *resolv, struct resolv_interface *dest ) {
97
-	intf_plug ( &resolv->intf, &dest->intf );
98
-}
99
-
100
-/**
101
- * Plug two name resolution interfaces together
102
- *
103
- * @v a			Name resolution interface A
104
- * @v b			Name resolution interface B
105
- */
106
-static inline __attribute__ (( always_inline )) void
107
-resolv_plug_plug ( struct resolv_interface *a, struct resolv_interface *b ) {
108
-	intf_plug_plug ( &a->intf, &b->intf );
109
-}
110
-
111
-/**
112
- * Unplug a name resolution interface
113
- *
114
- * @v resolv		Name resolution interface
115
- */
116
-static inline __attribute__ (( always_inline )) void
117
-resolv_unplug ( struct resolv_interface *resolv ) {
118
-	intf_plug ( &resolv->intf, &null_resolv.intf );
119
-}
120
-
121
-/**
122
- * Stop using a name resolution interface
123
- *
124
- * @v resolv		Name resolution interface
125
- *
126
- * After calling this method, no further messages will be received via
127
- * the interface.
128
- */
129
-static inline void resolv_nullify ( struct resolv_interface *resolv ) {
130
-	resolv->op = &null_resolv_ops;
131
-};
15
+struct sockaddr;
132 16
 
133 17
 /** A name resolver */
134 18
 struct resolver {
@@ -141,7 +25,7 @@ struct resolver {
141 25
 	 * @v sa		Socket address to complete
142 26
 	 * @ret rc		Return status code
143 27
 	 */
144
-	int ( * resolv ) ( struct resolv_interface *resolv, const char *name,
28
+	int ( * resolv ) ( struct interface *resolv, const char *name,
145 29
 			   struct sockaddr *sa );
146 30
 };
147 31
 
@@ -157,14 +41,11 @@ struct resolver {
157 41
 /** Register as a name resolver */
158 42
 #define __resolver( resolv_order ) __table_entry ( RESOLVERS, resolv_order )
159 43
 
160
-extern void resolv_done ( struct resolv_interface *resolv,
161
-			  struct sockaddr *sa, int rc );
162
-extern void ignore_resolv_done ( struct resolv_interface *resolv,
163
-			  struct sockaddr *sa, int rc );
164
-extern struct resolv_interface_operations null_resolv_ops;
165
-extern struct resolv_interface null_resolv;
44
+extern void resolv_done ( struct interface *intf, struct sockaddr *sa );
45
+#define resolv_done_TYPE( object_type ) \
46
+	typeof ( void ( object_type, struct sockaddr *sa ) )
166 47
 
167
-extern int resolv ( struct resolv_interface *resolv, const char *name,
48
+extern int resolv ( struct interface *resolv, const char *name,
168 49
 		    struct sockaddr *sa );
169 50
 
170 51
 #endif /* _IPXE_RESOLV_H */

+ 18
- 6
src/net/udp/dns.c 查看文件

@@ -58,7 +58,7 @@ struct dns_request {
58 58
 	/** Reference counter */
59 59
 	struct refcnt refcnt;
60 60
 	/** Name resolution interface */
61
-	struct resolv_interface resolv;
61
+	struct interface resolv;
62 62
 	/** Data transfer interface */
63 63
 	struct xfer_interface socket;
64 64
 	/** Retry timer */
@@ -93,8 +93,8 @@ static void dns_done ( struct dns_request *dns, int rc ) {
93 93
 	xfer_nullify ( &dns->socket );
94 94
 	xfer_close ( &dns->socket, rc );
95 95
 
96
-	/* Mark name resolution as complete */
97
-	resolv_done ( &dns->resolv, &dns->sa, rc );
96
+	/* Shut down interfaces */
97
+	intf_shutdown ( &dns->resolv, rc );
98 98
 }
99 99
 
100 100
 /**
@@ -377,6 +377,9 @@ static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
377 377
 			sin->sin_family = AF_INET;
378 378
 			sin->sin_addr = rr_info->a.in_addr;
379 379
 
380
+			/* Return resolved address */
381
+			resolv_done ( &dns->resolv, &dns->sa );
382
+
380 383
 			/* Mark operation as complete */
381 384
 			dns_done ( dns, 0 );
382 385
 			return 0;
@@ -468,6 +471,15 @@ static struct xfer_interface_operations dns_socket_operations = {
468 471
 	.deliver_raw	= dns_xfer_deliver_raw,
469 472
 };
470 473
 
474
+/** DNS resolver interface operations */
475
+static struct interface_operation dns_resolv_op[] = {
476
+	INTF_OP ( intf_close, struct dns_request *, dns_done ),
477
+};
478
+
479
+/** DNS resolver interface descriptor */
480
+static struct interface_descriptor dns_resolv_desc =
481
+	INTF_DESC ( struct dns_request, resolv, dns_resolv_op );
482
+
471 483
 /**
472 484
  * Resolve name using DNS
473 485
  *
@@ -476,7 +488,7 @@ static struct xfer_interface_operations dns_socket_operations = {
476 488
  * @v sa		Socket address to fill in
477 489
  * @ret rc		Return status code
478 490
  */
479
-static int dns_resolv ( struct resolv_interface *resolv,
491
+static int dns_resolv ( struct interface *resolv,
480 492
 			const char *name, struct sockaddr *sa ) {
481 493
 	struct dns_request *dns;
482 494
 	char *fqdn;
@@ -504,7 +516,7 @@ static int dns_resolv ( struct resolv_interface *resolv,
504 516
 		goto err_alloc_dns;
505 517
 	}
506 518
 	ref_init ( &dns->refcnt, NULL );
507
-	resolv_init ( &dns->resolv, &null_resolv_ops, &dns->refcnt );
519
+	intf_init ( &dns->resolv, &dns_resolv_desc, &dns->refcnt );
508 520
 	xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
509 521
 	timer_init ( &dns->timer, dns_timer_expired );
510 522
 	memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
@@ -530,7 +542,7 @@ static int dns_resolv ( struct resolv_interface *resolv,
530 542
 	dns_send_packet ( dns );
531 543
 
532 544
 	/* Attach parent interface, mortalise self, and return */
533
-	resolv_plug_plug ( &dns->resolv, resolv );
545
+	intf_plug_plug ( &dns->resolv, resolv );
534 546
 	ref_put ( &dns->refcnt );
535 547
 	free ( fqdn );
536 548
 	return 0;	

正在加载...
取消
保存