[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>
This commit is contained in:
parent
a03dd97e6b
commit
7b4fbd93a5
@ -7,54 +7,55 @@
|
|||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
static int comboot_resolv_rc;
|
struct comboot_resolver {
|
||||||
static struct in_addr comboot_resolv_addr;
|
struct interface intf;
|
||||||
|
int rc;
|
||||||
static void comboot_resolv_done ( struct resolv_interface *resolv,
|
struct in_addr addr;
|
||||||
struct sockaddr *sa, int rc ) {
|
|
||||||
struct sockaddr_in *sin;
|
|
||||||
|
|
||||||
resolv_unplug ( resolv );
|
|
||||||
|
|
||||||
if ( rc != 0 ) {
|
|
||||||
comboot_resolv_rc = rc;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sa->sa_family != AF_INET ) {
|
|
||||||
comboot_resolv_rc = -EAFNOSUPPORT;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sin = ( ( struct sockaddr_in * ) sa );
|
|
||||||
comboot_resolv_addr = sin->sin_addr;
|
|
||||||
|
|
||||||
comboot_resolv_rc = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct resolv_interface_operations comboot_resolv_ops = {
|
|
||||||
.done = comboot_resolv_done,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct resolv_interface comboot_resolver = {
|
static void comboot_resolv_close ( struct comboot_resolver *comboot_resolver,
|
||||||
.intf = {
|
int rc ) {
|
||||||
.dest = &null_resolv.intf,
|
comboot_resolver->rc = rc;
|
||||||
.refcnt = NULL,
|
intf_shutdown ( &comboot_resolver->intf, rc );
|
||||||
},
|
}
|
||||||
.op = &comboot_resolv_ops,
|
|
||||||
|
static void comboot_resolv_done ( struct comboot_resolver *comboot_resolver,
|
||||||
|
struct sockaddr *sa ) {
|
||||||
|
struct sockaddr_in *sin;
|
||||||
|
|
||||||
|
if ( sa->sa_family == AF_INET ) {
|
||||||
|
sin = ( ( struct sockaddr_in * ) sa );
|
||||||
|
comboot_resolver->addr = sin->sin_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct interface_operation comboot_resolv_op[] = {
|
||||||
|
INTF_OP ( intf_close, struct comboot_resolver *, comboot_resolv_close ),
|
||||||
|
INTF_OP ( resolv_done, struct comboot_resolver *, comboot_resolv_done ),
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct interface_descriptor comboot_resolv_desc =
|
||||||
|
INTF_DESC ( struct comboot_resolver, intf, comboot_resolv_op );
|
||||||
|
|
||||||
|
static struct comboot_resolver comboot_resolver = {
|
||||||
|
.intf = INTF_INIT ( comboot_resolv_desc ),
|
||||||
};
|
};
|
||||||
|
|
||||||
int comboot_resolv ( const char *name, struct in_addr *address ) {
|
int comboot_resolv ( const char *name, struct in_addr *address ) {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
comboot_resolv_rc = -EINPROGRESS;
|
comboot_resolver.rc = -EINPROGRESS;
|
||||||
|
comboot_resolver.addr.s_addr = 0;
|
||||||
|
|
||||||
if ( ( rc = resolv ( &comboot_resolver, name, NULL ) ) != 0 )
|
if ( ( rc = resolv ( &comboot_resolver.intf, name, NULL ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
while ( comboot_resolv_rc == -EINPROGRESS )
|
while ( comboot_resolver.rc == -EINPROGRESS )
|
||||||
step();
|
step();
|
||||||
|
|
||||||
*address = comboot_resolv_addr;
|
if ( ! comboot_resolver.addr.s_addr )
|
||||||
return comboot_resolv_rc;
|
return -EAFNOSUPPORT;
|
||||||
|
|
||||||
|
*address = comboot_resolver.addr;
|
||||||
|
return comboot_resolver.rc;
|
||||||
}
|
}
|
||||||
|
@ -42,47 +42,29 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name resolution completed
|
* Name resolved
|
||||||
*
|
*
|
||||||
* @v resolv Name resolution interface
|
* @v intf Object interface
|
||||||
* @v sa Completed socket address (if successful)
|
* @v sa Completed socket address (if successful)
|
||||||
* @v rc Final status code
|
|
||||||
*/
|
*/
|
||||||
void resolv_done ( struct resolv_interface *resolv, struct sockaddr *sa,
|
void resolv_done ( struct interface *intf, struct sockaddr *sa ) {
|
||||||
int rc ) {
|
struct interface *dest;
|
||||||
struct resolv_interface *dest = resolv_get_dest ( resolv );
|
resolv_done_TYPE ( void * ) *op =
|
||||||
|
intf_get_dest_op ( intf, resolv_done, &dest );
|
||||||
|
void *object = intf_object ( dest );
|
||||||
|
|
||||||
resolv_unplug ( resolv );
|
DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " resolv_done\n",
|
||||||
dest->op->done ( dest, sa, rc );
|
INTF_INTF_DBG ( intf, dest ) );
|
||||||
resolv_put ( dest );
|
|
||||||
|
if ( op ) {
|
||||||
|
op ( object, sa );
|
||||||
|
} else {
|
||||||
|
/* Default is to ignore resolutions */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
intf_put ( dest );
|
||||||
* Ignore name resolution done() event
|
|
||||||
*
|
|
||||||
* @v resolv Name resolution interface
|
|
||||||
* @v sa Completed socket address (if successful)
|
|
||||||
* @v rc Final status code
|
|
||||||
*/
|
|
||||||
void ignore_resolv_done ( struct resolv_interface *resolv __unused,
|
|
||||||
struct sockaddr *sa __unused, int rc __unused ) {
|
|
||||||
/* Do nothing */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Null name resolution interface operations */
|
|
||||||
struct resolv_interface_operations null_resolv_ops = {
|
|
||||||
.done = ignore_resolv_done,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Null name resolution interface */
|
|
||||||
struct resolv_interface null_resolv = {
|
|
||||||
.intf = {
|
|
||||||
.dest = &null_resolv.intf,
|
|
||||||
.refcnt = NULL,
|
|
||||||
},
|
|
||||||
.op = &null_resolv_ops,
|
|
||||||
};
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* Numeric name resolver
|
* Numeric name resolver
|
||||||
@ -95,7 +77,7 @@ struct numeric_resolv {
|
|||||||
/** Reference counter */
|
/** Reference counter */
|
||||||
struct refcnt refcnt;
|
struct refcnt refcnt;
|
||||||
/** Name resolution interface */
|
/** Name resolution interface */
|
||||||
struct resolv_interface resolv;
|
struct interface resolv;
|
||||||
/** Process */
|
/** Process */
|
||||||
struct process process;
|
struct process process;
|
||||||
/** Completed socket address */
|
/** Completed socket address */
|
||||||
@ -108,11 +90,13 @@ static void numeric_step ( struct process *process ) {
|
|||||||
struct numeric_resolv *numeric =
|
struct numeric_resolv *numeric =
|
||||||
container_of ( process, struct numeric_resolv, process );
|
container_of ( process, struct numeric_resolv, process );
|
||||||
|
|
||||||
resolv_done ( &numeric->resolv, &numeric->sa, numeric->rc );
|
|
||||||
process_del ( process );
|
process_del ( process );
|
||||||
|
if ( numeric->rc == 0 )
|
||||||
|
resolv_done ( &numeric->resolv, &numeric->sa );
|
||||||
|
intf_shutdown ( &numeric->resolv, numeric->rc );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int numeric_resolv ( struct resolv_interface *resolv,
|
static int numeric_resolv ( struct interface *resolv,
|
||||||
const char *name, struct sockaddr *sa ) {
|
const char *name, struct sockaddr *sa ) {
|
||||||
struct numeric_resolv *numeric;
|
struct numeric_resolv *numeric;
|
||||||
struct sockaddr_in *sin;
|
struct sockaddr_in *sin;
|
||||||
@ -122,7 +106,7 @@ static int numeric_resolv ( struct resolv_interface *resolv,
|
|||||||
if ( ! numeric )
|
if ( ! numeric )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
ref_init ( &numeric->refcnt, NULL );
|
ref_init ( &numeric->refcnt, NULL );
|
||||||
resolv_init ( &numeric->resolv, &null_resolv_ops, &numeric->refcnt );
|
intf_init ( &numeric->resolv, &null_intf_desc, &numeric->refcnt );
|
||||||
process_init ( &numeric->process, numeric_step, &numeric->refcnt );
|
process_init ( &numeric->process, numeric_step, &numeric->refcnt );
|
||||||
memcpy ( &numeric->sa, sa, sizeof ( numeric->sa ) );
|
memcpy ( &numeric->sa, sa, sizeof ( numeric->sa ) );
|
||||||
|
|
||||||
@ -131,12 +115,14 @@ static int numeric_resolv ( struct resolv_interface *resolv,
|
|||||||
|
|
||||||
/* Attempt to resolve name */
|
/* Attempt to resolve name */
|
||||||
sin = ( ( struct sockaddr_in * ) &numeric->sa );
|
sin = ( ( struct sockaddr_in * ) &numeric->sa );
|
||||||
|
if ( inet_aton ( name, &sin->sin_addr ) != 0 ) {
|
||||||
sin->sin_family = AF_INET;
|
sin->sin_family = AF_INET;
|
||||||
if ( inet_aton ( name, &sin->sin_addr ) == 0 )
|
} else {
|
||||||
numeric->rc = -EINVAL;
|
numeric->rc = -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Attach to parent interface, mortalise self, and return */
|
/* Attach to parent interface, mortalise self, and return */
|
||||||
resolv_plug_plug ( &numeric->resolv, resolv );
|
intf_plug_plug ( &numeric->resolv, resolv );
|
||||||
ref_put ( &numeric->refcnt );
|
ref_put ( &numeric->refcnt );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -158,10 +144,10 @@ struct resolv_mux {
|
|||||||
/** Reference counter */
|
/** Reference counter */
|
||||||
struct refcnt refcnt;
|
struct refcnt refcnt;
|
||||||
/** Parent name resolution interface */
|
/** Parent name resolution interface */
|
||||||
struct resolv_interface parent;
|
struct interface parent;
|
||||||
|
|
||||||
/** Child name resolution interface */
|
/** Child name resolution interface */
|
||||||
struct resolv_interface child;
|
struct interface child;
|
||||||
/** Current child resolver */
|
/** Current child resolver */
|
||||||
struct resolver *resolver;
|
struct resolver *resolver;
|
||||||
|
|
||||||
@ -180,7 +166,7 @@ struct resolv_mux {
|
|||||||
* @v mux Name resolution multiplexer
|
* @v mux Name resolution multiplexer
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static int resolv_mux_try ( struct resolv_mux *mux ) {
|
static int resmux_try ( struct resolv_mux *mux ) {
|
||||||
struct resolver *resolver = mux->resolver;
|
struct resolver *resolver = mux->resolver;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -197,19 +183,31 @@ static int resolv_mux_try ( struct resolv_mux *mux ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle done() event from child name resolver
|
* Child resolved name
|
||||||
*
|
*
|
||||||
* @v resolv Child name resolution interface
|
* @v mux Name resolution multiplexer
|
||||||
* @v sa Completed socket address (if successful)
|
* @v sa Completed socket address
|
||||||
* @v rc Final status code
|
|
||||||
*/
|
*/
|
||||||
static void resolv_mux_done ( struct resolv_interface *resolv,
|
static void resmux_child_resolv_done ( struct resolv_mux *mux,
|
||||||
struct sockaddr *sa, int rc ) {
|
struct sockaddr *sa ) {
|
||||||
struct resolv_mux *mux =
|
|
||||||
container_of ( resolv, struct resolv_mux, child );
|
|
||||||
|
|
||||||
/* Unplug child */
|
DBGC ( mux, "RESOLV %p resolved \"%s\" using method %s\n",
|
||||||
resolv_unplug ( &mux->child );
|
mux, mux->name, mux->resolver->name );
|
||||||
|
|
||||||
|
/* Pass resolution to parent */
|
||||||
|
resolv_done ( &mux->parent, sa );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child finished resolution
|
||||||
|
*
|
||||||
|
* @v mux Name resolution multiplexer
|
||||||
|
* @v rc Return status code
|
||||||
|
*/
|
||||||
|
static void resmux_child_close ( struct resolv_mux *mux, int rc ) {
|
||||||
|
|
||||||
|
/* Restart child interface */
|
||||||
|
intf_restart ( &mux->child, rc );
|
||||||
|
|
||||||
/* If this resolution succeeded, stop now */
|
/* If this resolution succeeded, stop now */
|
||||||
if ( rc == 0 ) {
|
if ( rc == 0 ) {
|
||||||
@ -224,21 +222,26 @@ static void resolv_mux_done ( struct resolv_interface *resolv,
|
|||||||
DBGC ( mux, "RESOLV %p failed to resolve name\n", mux );
|
DBGC ( mux, "RESOLV %p failed to resolve name\n", mux );
|
||||||
goto finished;
|
goto finished;
|
||||||
}
|
}
|
||||||
if ( ( rc = resolv_mux_try ( mux ) ) != 0 )
|
if ( ( rc = resmux_try ( mux ) ) != 0 )
|
||||||
goto finished;
|
goto finished;
|
||||||
|
|
||||||
/* Next resolver is now running */
|
/* Next resolver is now running */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
finished:
|
finished:
|
||||||
resolv_done ( &mux->parent, sa, rc );
|
intf_shutdown ( &mux->parent, rc );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Name resolution multiplexer operations */
|
/** Name resolution multiplexer child interface operations */
|
||||||
static struct resolv_interface_operations resolv_mux_child_ops = {
|
static struct interface_operation resmux_child_op[] = {
|
||||||
.done = resolv_mux_done,
|
INTF_OP ( resolv_done, struct resolv_mux *, resmux_child_resolv_done ),
|
||||||
|
INTF_OP ( intf_close, struct resolv_mux *, resmux_child_close ),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Name resolution multiplexer child interface descriptor */
|
||||||
|
static struct interface_descriptor resmux_child_desc =
|
||||||
|
INTF_DESC ( struct resolv_mux, child, resmux_child_op );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start name resolution
|
* Start name resolution
|
||||||
*
|
*
|
||||||
@ -247,7 +250,7 @@ static struct resolv_interface_operations resolv_mux_child_ops = {
|
|||||||
* @v sa Socket address to complete
|
* @v sa Socket address to complete
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int resolv ( struct resolv_interface *resolv, const char *name,
|
int resolv ( struct interface *resolv, const char *name,
|
||||||
struct sockaddr *sa ) {
|
struct sockaddr *sa ) {
|
||||||
struct resolv_mux *mux;
|
struct resolv_mux *mux;
|
||||||
size_t name_len = ( strlen ( name ) + 1 );
|
size_t name_len = ( strlen ( name ) + 1 );
|
||||||
@ -258,9 +261,10 @@ int resolv ( struct resolv_interface *resolv, const char *name,
|
|||||||
if ( ! mux )
|
if ( ! mux )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
ref_init ( &mux->refcnt, NULL );
|
ref_init ( &mux->refcnt, NULL );
|
||||||
resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
|
intf_init ( &mux->parent, &null_intf_desc, &mux->refcnt );
|
||||||
resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
|
intf_init ( &mux->child, &resmux_child_desc, &mux->refcnt );
|
||||||
mux->resolver = table_start ( RESOLVERS );
|
mux->resolver = table_start ( RESOLVERS );
|
||||||
|
if ( sa )
|
||||||
memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
|
memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
|
||||||
memcpy ( mux->name, name, name_len );
|
memcpy ( mux->name, name, name_len );
|
||||||
|
|
||||||
@ -270,11 +274,11 @@ int resolv ( struct resolv_interface *resolv, const char *name,
|
|||||||
* least one resolver (the numeric resolver), so no need to
|
* least one resolver (the numeric resolver), so no need to
|
||||||
* check for the zero-resolvers-available case.
|
* check for the zero-resolvers-available case.
|
||||||
*/
|
*/
|
||||||
if ( ( rc = resolv_mux_try ( mux ) ) != 0 )
|
if ( ( rc = resmux_try ( mux ) ) != 0 )
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* Attach parent interface, mortalise self, and return */
|
/* Attach parent interface, mortalise self, and return */
|
||||||
resolv_plug_plug ( &mux->parent, resolv );
|
intf_plug_plug ( &mux->parent, resolv );
|
||||||
ref_put ( &mux->refcnt );
|
ref_put ( &mux->refcnt );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -297,7 +301,7 @@ struct named_socket {
|
|||||||
/** Data transfer interface */
|
/** Data transfer interface */
|
||||||
struct xfer_interface xfer;
|
struct xfer_interface xfer;
|
||||||
/** Name resolution interface */
|
/** Name resolution interface */
|
||||||
struct resolv_interface resolv;
|
struct interface resolv;
|
||||||
/** Communication semantics (e.g. SOCK_STREAM) */
|
/** Communication semantics (e.g. SOCK_STREAM) */
|
||||||
int semantics;
|
int semantics;
|
||||||
/** Stored local socket address, if applicable */
|
/** Stored local socket address, if applicable */
|
||||||
@ -307,15 +311,14 @@ struct named_socket {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finish using named socket
|
* Terminate named socket opener
|
||||||
*
|
*
|
||||||
* @v named Named socket
|
* @v named Named socket
|
||||||
* @v rc Reason for finish
|
* @v rc Reason for termination
|
||||||
*/
|
*/
|
||||||
static void named_done ( struct named_socket *named, int rc ) {
|
static void named_close ( struct named_socket *named, int rc ) {
|
||||||
|
/* Shut down interfaces */
|
||||||
/* Close all interfaces */
|
intf_shutdown ( &named->resolv, rc );
|
||||||
resolv_nullify ( &named->resolv );
|
|
||||||
xfer_nullify ( &named->xfer );
|
xfer_nullify ( &named->xfer );
|
||||||
xfer_close ( &named->xfer, rc );
|
xfer_close ( &named->xfer, rc );
|
||||||
}
|
}
|
||||||
@ -330,7 +333,7 @@ static void named_xfer_close ( struct xfer_interface *xfer, int rc ) {
|
|||||||
struct named_socket *named =
|
struct named_socket *named =
|
||||||
container_of ( xfer, struct named_socket, xfer );
|
container_of ( xfer, struct named_socket, xfer );
|
||||||
|
|
||||||
named_done ( named, rc );
|
named_close ( named, rc );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Named socket opener data transfer interface operations */
|
/** Named socket opener data transfer interface operations */
|
||||||
@ -344,34 +347,46 @@ static struct xfer_interface_operations named_xfer_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle done() event
|
* Name resolved
|
||||||
*
|
*
|
||||||
* @v resolv Name resolution interface
|
* @v named Named socket
|
||||||
* @v sa Completed socket address (if successful)
|
* @v sa Completed socket address
|
||||||
* @v rc Final status code
|
|
||||||
*/
|
*/
|
||||||
static void named_resolv_done ( struct resolv_interface *resolv,
|
static void named_resolv_done ( struct named_socket *named,
|
||||||
struct sockaddr *sa, int rc ) {
|
struct sockaddr *sa ) {
|
||||||
struct named_socket *named =
|
int rc;
|
||||||
container_of ( resolv, struct named_socket, resolv );
|
|
||||||
|
|
||||||
/* Redirect if name resolution was successful */
|
/* Nullify data transfer interface */
|
||||||
if ( rc == 0 ) {
|
xfer_nullify ( &named->xfer );
|
||||||
rc = xfer_redirect ( &named->xfer, LOCATION_SOCKET,
|
|
||||||
|
/* Redirect data-xfer interface */
|
||||||
|
if ( ( rc = xfer_redirect ( &named->xfer, LOCATION_SOCKET,
|
||||||
named->semantics, sa,
|
named->semantics, sa,
|
||||||
( named->have_local ?
|
( named->have_local ?
|
||||||
&named->local : NULL ) );
|
&named->local : NULL ) ) ) != 0 ) {
|
||||||
|
/* Redirection failed - do not unplug data-xfer interface */
|
||||||
|
DBGC ( named, "NAMED %p could not redirect: %s\n",
|
||||||
|
named, strerror ( rc ) );
|
||||||
|
} else {
|
||||||
|
/* Redirection succeeded - unplug data-xfer interface */
|
||||||
|
DBGC ( named, "NAMED %p redirected successfully\n", named );
|
||||||
|
xfer_unplug ( &named->xfer );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Terminate resolution */
|
/* Terminate named socket opener */
|
||||||
named_done ( named, rc );
|
named_close ( named, rc );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Named socket opener name resolution interface operations */
|
/** Named socket opener resolver interface operations */
|
||||||
static struct resolv_interface_operations named_resolv_ops = {
|
static struct interface_operation named_resolv_op[] = {
|
||||||
.done = named_resolv_done,
|
INTF_OP ( intf_close, struct named_socket *, named_close ),
|
||||||
|
INTF_OP ( resolv_done, struct named_socket *, named_resolv_done ),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Named socket opener resolver interface descriptor */
|
||||||
|
static struct interface_descriptor named_resolv_desc =
|
||||||
|
INTF_DESC ( struct named_socket, resolv, named_resolv_op );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open named socket
|
* Open named socket
|
||||||
*
|
*
|
||||||
@ -393,14 +408,14 @@ int xfer_open_named_socket ( struct xfer_interface *xfer, int semantics,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
ref_init ( &named->refcnt, NULL );
|
ref_init ( &named->refcnt, NULL );
|
||||||
xfer_init ( &named->xfer, &named_xfer_ops, &named->refcnt );
|
xfer_init ( &named->xfer, &named_xfer_ops, &named->refcnt );
|
||||||
resolv_init ( &named->resolv, &named_resolv_ops, &named->refcnt );
|
intf_init ( &named->resolv, &named_resolv_desc, &named->refcnt );
|
||||||
named->semantics = semantics;
|
named->semantics = semantics;
|
||||||
if ( local ) {
|
if ( local ) {
|
||||||
memcpy ( &named->local, local, sizeof ( named->local ) );
|
memcpy ( &named->local, local, sizeof ( named->local ) );
|
||||||
named->have_local = 1;
|
named->have_local = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBGC ( named, "RESOLV %p opening named socket \"%s\"\n",
|
DBGC ( named, "NAMED %p opening \"%s\"\n",
|
||||||
named, name );
|
named, name );
|
||||||
|
|
||||||
/* Start name resolution */
|
/* Start name resolution */
|
||||||
|
@ -9,126 +9,10 @@
|
|||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
#include <ipxe/refcnt.h>
|
|
||||||
#include <ipxe/interface.h>
|
#include <ipxe/interface.h>
|
||||||
#include <ipxe/tables.h>
|
#include <ipxe/tables.h>
|
||||||
#include <ipxe/socket.h>
|
|
||||||
|
|
||||||
struct resolv_interface;
|
struct sockaddr;
|
||||||
|
|
||||||
/** Name resolution interface operations */
|
|
||||||
struct resolv_interface_operations {
|
|
||||||
/** Name resolution completed
|
|
||||||
*
|
|
||||||
* @v resolv Name resolution interface
|
|
||||||
* @v sa Completed socket address (if successful)
|
|
||||||
* @v rc Final status code
|
|
||||||
*/
|
|
||||||
void ( * done ) ( struct resolv_interface *resolv,
|
|
||||||
struct sockaddr *sa, int rc );
|
|
||||||
};
|
|
||||||
|
|
||||||
/** A name resolution interface */
|
|
||||||
struct resolv_interface {
|
|
||||||
/** Generic object communication interface */
|
|
||||||
struct interface intf;
|
|
||||||
/** Operations for received messages */
|
|
||||||
struct resolv_interface_operations *op;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct resolv_interface null_resolv;
|
|
||||||
extern struct resolv_interface_operations null_resolv_ops;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise a name resolution interface
|
|
||||||
*
|
|
||||||
* @v resolv Name resolution interface
|
|
||||||
* @v op Name resolution interface operations
|
|
||||||
* @v refcnt Containing object reference counter, or NULL
|
|
||||||
*/
|
|
||||||
static inline void resolv_init ( struct resolv_interface *resolv,
|
|
||||||
struct resolv_interface_operations *op,
|
|
||||||
struct refcnt *refcnt ) {
|
|
||||||
resolv->intf.dest = &null_resolv.intf;
|
|
||||||
resolv->intf.refcnt = refcnt;
|
|
||||||
resolv->op = op;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get name resolution interface from generic object communication interface
|
|
||||||
*
|
|
||||||
* @v intf Generic object communication interface
|
|
||||||
* @ret resolv Name resolution interface
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) struct resolv_interface *
|
|
||||||
intf_to_resolv ( struct interface *intf ) {
|
|
||||||
return container_of ( intf, struct resolv_interface, intf );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get reference to destination name resolution interface
|
|
||||||
*
|
|
||||||
* @v resolv Name resolution interface
|
|
||||||
* @ret dest Destination interface
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) struct resolv_interface *
|
|
||||||
resolv_get_dest ( struct resolv_interface *resolv ) {
|
|
||||||
return intf_to_resolv ( intf_get ( resolv->intf.dest ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drop reference to name resolution interface
|
|
||||||
*
|
|
||||||
* @v resolv name resolution interface
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) void
|
|
||||||
resolv_put ( struct resolv_interface *resolv ) {
|
|
||||||
intf_put ( &resolv->intf );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plug a name resolution interface into a new destination interface
|
|
||||||
*
|
|
||||||
* @v resolv Name resolution interface
|
|
||||||
* @v dest New destination interface
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) void
|
|
||||||
resolv_plug ( struct resolv_interface *resolv, struct resolv_interface *dest ) {
|
|
||||||
intf_plug ( &resolv->intf, &dest->intf );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plug two name resolution interfaces together
|
|
||||||
*
|
|
||||||
* @v a Name resolution interface A
|
|
||||||
* @v b Name resolution interface B
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) void
|
|
||||||
resolv_plug_plug ( struct resolv_interface *a, struct resolv_interface *b ) {
|
|
||||||
intf_plug_plug ( &a->intf, &b->intf );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unplug a name resolution interface
|
|
||||||
*
|
|
||||||
* @v resolv Name resolution interface
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) void
|
|
||||||
resolv_unplug ( struct resolv_interface *resolv ) {
|
|
||||||
intf_plug ( &resolv->intf, &null_resolv.intf );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop using a name resolution interface
|
|
||||||
*
|
|
||||||
* @v resolv Name resolution interface
|
|
||||||
*
|
|
||||||
* After calling this method, no further messages will be received via
|
|
||||||
* the interface.
|
|
||||||
*/
|
|
||||||
static inline void resolv_nullify ( struct resolv_interface *resolv ) {
|
|
||||||
resolv->op = &null_resolv_ops;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** A name resolver */
|
/** A name resolver */
|
||||||
struct resolver {
|
struct resolver {
|
||||||
@ -141,7 +25,7 @@ struct resolver {
|
|||||||
* @v sa Socket address to complete
|
* @v sa Socket address to complete
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int ( * resolv ) ( struct resolv_interface *resolv, const char *name,
|
int ( * resolv ) ( struct interface *resolv, const char *name,
|
||||||
struct sockaddr *sa );
|
struct sockaddr *sa );
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,14 +41,11 @@ struct resolver {
|
|||||||
/** Register as a name resolver */
|
/** Register as a name resolver */
|
||||||
#define __resolver( resolv_order ) __table_entry ( RESOLVERS, resolv_order )
|
#define __resolver( resolv_order ) __table_entry ( RESOLVERS, resolv_order )
|
||||||
|
|
||||||
extern void resolv_done ( struct resolv_interface *resolv,
|
extern void resolv_done ( struct interface *intf, struct sockaddr *sa );
|
||||||
struct sockaddr *sa, int rc );
|
#define resolv_done_TYPE( object_type ) \
|
||||||
extern void ignore_resolv_done ( struct resolv_interface *resolv,
|
typeof ( void ( object_type, struct sockaddr *sa ) )
|
||||||
struct sockaddr *sa, int rc );
|
|
||||||
extern struct resolv_interface_operations null_resolv_ops;
|
|
||||||
extern struct resolv_interface null_resolv;
|
|
||||||
|
|
||||||
extern int resolv ( struct resolv_interface *resolv, const char *name,
|
extern int resolv ( struct interface *resolv, const char *name,
|
||||||
struct sockaddr *sa );
|
struct sockaddr *sa );
|
||||||
|
|
||||||
#endif /* _IPXE_RESOLV_H */
|
#endif /* _IPXE_RESOLV_H */
|
||||||
|
@ -58,7 +58,7 @@ struct dns_request {
|
|||||||
/** Reference counter */
|
/** Reference counter */
|
||||||
struct refcnt refcnt;
|
struct refcnt refcnt;
|
||||||
/** Name resolution interface */
|
/** Name resolution interface */
|
||||||
struct resolv_interface resolv;
|
struct interface resolv;
|
||||||
/** Data transfer interface */
|
/** Data transfer interface */
|
||||||
struct xfer_interface socket;
|
struct xfer_interface socket;
|
||||||
/** Retry timer */
|
/** Retry timer */
|
||||||
@ -93,8 +93,8 @@ static void dns_done ( struct dns_request *dns, int rc ) {
|
|||||||
xfer_nullify ( &dns->socket );
|
xfer_nullify ( &dns->socket );
|
||||||
xfer_close ( &dns->socket, rc );
|
xfer_close ( &dns->socket, rc );
|
||||||
|
|
||||||
/* Mark name resolution as complete */
|
/* Shut down interfaces */
|
||||||
resolv_done ( &dns->resolv, &dns->sa, rc );
|
intf_shutdown ( &dns->resolv, rc );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,6 +377,9 @@ static int dns_xfer_deliver_raw ( struct xfer_interface *socket,
|
|||||||
sin->sin_family = AF_INET;
|
sin->sin_family = AF_INET;
|
||||||
sin->sin_addr = rr_info->a.in_addr;
|
sin->sin_addr = rr_info->a.in_addr;
|
||||||
|
|
||||||
|
/* Return resolved address */
|
||||||
|
resolv_done ( &dns->resolv, &dns->sa );
|
||||||
|
|
||||||
/* Mark operation as complete */
|
/* Mark operation as complete */
|
||||||
dns_done ( dns, 0 );
|
dns_done ( dns, 0 );
|
||||||
return 0;
|
return 0;
|
||||||
@ -468,6 +471,15 @@ static struct xfer_interface_operations dns_socket_operations = {
|
|||||||
.deliver_raw = dns_xfer_deliver_raw,
|
.deliver_raw = dns_xfer_deliver_raw,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** DNS resolver interface operations */
|
||||||
|
static struct interface_operation dns_resolv_op[] = {
|
||||||
|
INTF_OP ( intf_close, struct dns_request *, dns_done ),
|
||||||
|
};
|
||||||
|
|
||||||
|
/** DNS resolver interface descriptor */
|
||||||
|
static struct interface_descriptor dns_resolv_desc =
|
||||||
|
INTF_DESC ( struct dns_request, resolv, dns_resolv_op );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve name using DNS
|
* Resolve name using DNS
|
||||||
*
|
*
|
||||||
@ -476,7 +488,7 @@ static struct xfer_interface_operations dns_socket_operations = {
|
|||||||
* @v sa Socket address to fill in
|
* @v sa Socket address to fill in
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static int dns_resolv ( struct resolv_interface *resolv,
|
static int dns_resolv ( struct interface *resolv,
|
||||||
const char *name, struct sockaddr *sa ) {
|
const char *name, struct sockaddr *sa ) {
|
||||||
struct dns_request *dns;
|
struct dns_request *dns;
|
||||||
char *fqdn;
|
char *fqdn;
|
||||||
@ -504,7 +516,7 @@ static int dns_resolv ( struct resolv_interface *resolv,
|
|||||||
goto err_alloc_dns;
|
goto err_alloc_dns;
|
||||||
}
|
}
|
||||||
ref_init ( &dns->refcnt, NULL );
|
ref_init ( &dns->refcnt, NULL );
|
||||||
resolv_init ( &dns->resolv, &null_resolv_ops, &dns->refcnt );
|
intf_init ( &dns->resolv, &dns_resolv_desc, &dns->refcnt );
|
||||||
xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
|
xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
|
||||||
timer_init ( &dns->timer, dns_timer_expired );
|
timer_init ( &dns->timer, dns_timer_expired );
|
||||||
memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
|
memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
|
||||||
@ -530,7 +542,7 @@ static int dns_resolv ( struct resolv_interface *resolv,
|
|||||||
dns_send_packet ( dns );
|
dns_send_packet ( dns );
|
||||||
|
|
||||||
/* Attach parent interface, mortalise self, and return */
|
/* Attach parent interface, mortalise self, and return */
|
||||||
resolv_plug_plug ( &dns->resolv, resolv );
|
intf_plug_plug ( &dns->resolv, resolv );
|
||||||
ref_put ( &dns->refcnt );
|
ref_put ( &dns->refcnt );
|
||||||
free ( fqdn );
|
free ( fqdn );
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user