resolv.h

Go to the documentation of this file.
00001 #ifndef _GPXE_RESOLV_H
00002 #define _GPXE_RESOLV_H
00003 
00004 /** @file
00005  *
00006  * Name resolution
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 #include <gpxe/refcnt.h>
00013 #include <gpxe/interface.h>
00014 #include <gpxe/tables.h>
00015 #include <gpxe/socket.h>
00016 
00017 struct resolv_interface;
00018 
00019 /** Name resolution interface operations */
00020 struct resolv_interface_operations {
00021         /** Name resolution completed
00022          *
00023          * @v resolv            Name resolution interface
00024          * @v sa                Completed socket address (if successful)
00025          * @v rc                Final status code
00026          */
00027         void ( * done ) ( struct resolv_interface *resolv,
00028                           struct sockaddr *sa, int rc );
00029 };
00030 
00031 /** A name resolution interface */
00032 struct resolv_interface {
00033         /** Generic object communication interface */
00034         struct interface intf;
00035         /** Operations for received messages */
00036         struct resolv_interface_operations *op;
00037 };
00038 
00039 extern struct resolv_interface null_resolv;
00040 extern struct resolv_interface_operations null_resolv_ops;
00041 
00042 /**
00043  * Initialise a name resolution interface
00044  *
00045  * @v resolv            Name resolution interface
00046  * @v op                Name resolution interface operations
00047  * @v refcnt            Containing object reference counter, or NULL
00048  */
00049 static inline void resolv_init ( struct resolv_interface *resolv,
00050                                  struct resolv_interface_operations *op,
00051                                  struct refcnt *refcnt ) {
00052         resolv->intf.dest = &null_resolv.intf;
00053         resolv->intf.refcnt = refcnt;
00054         resolv->op = op;
00055 }
00056 
00057 /**
00058  * Get name resolution interface from generic object communication interface
00059  *
00060  * @v intf              Generic object communication interface
00061  * @ret resolv          Name resolution interface
00062  */
00063 static inline __attribute__ (( always_inline )) struct resolv_interface *
00064 intf_to_resolv ( struct interface *intf ) {
00065         return container_of ( intf, struct resolv_interface, intf );
00066 }
00067 
00068 /**
00069  * Get reference to destination name resolution interface
00070  *
00071  * @v resolv            Name resolution interface
00072  * @ret dest            Destination interface
00073  */
00074 static inline __attribute__ (( always_inline )) struct resolv_interface *
00075 resolv_get_dest ( struct resolv_interface *resolv ) {
00076         return intf_to_resolv ( intf_get ( resolv->intf.dest ) );
00077 }
00078 
00079 /**
00080  * Drop reference to name resolution interface
00081  *
00082  * @v resolv            name resolution interface
00083  */
00084 static inline __attribute__ (( always_inline )) void
00085 resolv_put ( struct resolv_interface *resolv ) {
00086         intf_put ( &resolv->intf );
00087 }
00088 
00089 /**
00090  * Plug a name resolution interface into a new destination interface
00091  *
00092  * @v resolv            Name resolution interface
00093  * @v dest              New destination interface
00094  */
00095 static inline __attribute__ (( always_inline )) void
00096 resolv_plug ( struct resolv_interface *resolv, struct resolv_interface *dest ) {
00097         plug ( &resolv->intf, &dest->intf );
00098 }
00099 
00100 /**
00101  * Plug two name resolution interfaces together
00102  *
00103  * @v a                 Name resolution interface A
00104  * @v b                 Name resolution interface B
00105  */
00106 static inline __attribute__ (( always_inline )) void
00107 resolv_plug_plug ( struct resolv_interface *a, struct resolv_interface *b ) {
00108         plug_plug ( &a->intf, &b->intf );
00109 }
00110 
00111 /**
00112  * Unplug a name resolution interface
00113  *
00114  * @v resolv            Name resolution interface
00115  */
00116 static inline __attribute__ (( always_inline )) void
00117 resolv_unplug ( struct resolv_interface *resolv ) {
00118         plug ( &resolv->intf, &null_resolv.intf );
00119 }
00120 
00121 /**
00122  * Stop using a name resolution interface
00123  *
00124  * @v resolv            Name resolution interface
00125  *
00126  * After calling this method, no further messages will be received via
00127  * the interface.
00128  */
00129 static inline void resolv_nullify ( struct resolv_interface *resolv ) {
00130         resolv->op = &null_resolv_ops;
00131 };
00132 
00133 /** A name resolver */
00134 struct resolver {
00135         /** Name of this resolver (e.g. "DNS") */
00136         const char *name;
00137         /** Start name resolution
00138          *
00139          * @v resolv            Name resolution interface
00140          * @v name              Name to resolve
00141          * @v sa                Socket address to complete
00142          * @ret rc              Return status code
00143          */
00144         int ( * resolv ) ( struct resolv_interface *resolv, const char *name,
00145                            struct sockaddr *sa );
00146 };
00147 
00148 /** Numeric resolver priority */
00149 #define RESOLV_NUMERIC 01
00150 
00151 /** Normal resolver priority */
00152 #define RESOLV_NORMAL 02
00153 
00154 /** Resolvers table */
00155 #define RESOLVERS __table ( struct resolver, "resolvers" )
00156 
00157 /** Register as a name resolver */
00158 #define __resolver( resolv_order ) __table_entry ( RESOLVERS, resolv_order )
00159 
00160 extern void resolv_done ( struct resolv_interface *resolv,
00161                           struct sockaddr *sa, int rc );
00162 extern void ignore_resolv_done ( struct resolv_interface *resolv,
00163                           struct sockaddr *sa, int rc );
00164 extern struct resolv_interface_operations null_resolv_ops;
00165 extern struct resolv_interface null_resolv;
00166 
00167 extern int resolv ( struct resolv_interface *resolv, const char *name,
00168                     struct sockaddr *sa );
00169 
00170 #endif /* _GPXE_RESOLV_H */

Generated on Tue Apr 6 20:01:08 2010 for gPXE by  doxygen 1.5.7.1