|
@@ -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 */
|