iPXE
Data Structures | Functions | Variables
fcns.c File Reference

Fibre Channel name server lookups. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/interface.h>
#include <ipxe/iobuf.h>
#include <ipxe/process.h>
#include <ipxe/xfer.h>
#include <ipxe/fc.h>
#include <ipxe/fcns.h>

Go to the source code of this file.

Data Structures

struct  fc_ns_query
 A Fibre Channel name server query. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void fc_ns_query_free (struct refcnt *refcnt)
 Free name server query. More...
 
static void fc_ns_query_close (struct fc_ns_query *query, int rc)
 Close name server query. More...
 
static int fc_ns_query_deliver (struct fc_ns_query *query, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Receive name server query response. More...
 
static void fc_ns_query_step (struct fc_ns_query *query)
 Name server query process. More...
 
int fc_ns_query (struct fc_peer *peer, struct fc_port *port, int(*done)(struct fc_peer *peer, struct fc_port *port, struct fc_port_id *peer_port_id))
 Issue Fibre Channel name server query. More...
 

Variables

static struct interface_operation fc_ns_query_xchg_op []
 Name server exchange interface operations. More...
 
static struct interface_descriptor fc_ns_query_xchg_desc
 Name server exchange interface descriptor. More...
 
static struct process_descriptor fc_ns_query_process_desc
 Name server process descriptor. More...
 

Detailed Description

Fibre Channel name server lookups.

Definition in file fcns.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ fc_ns_query_free()

static void fc_ns_query_free ( struct refcnt refcnt)
static

Free name server query.

Parameters
refcntReference count

Definition at line 74 of file fcns.c.

74  {
75  struct fc_ns_query *query =
77 
78  fc_peer_put ( query->peer );
79  fc_port_put ( query->port );
80  free ( query );
81 }
A Fibre Channel name server query.
Definition: fcns.c:45
static void fc_port_put(struct fc_port *port)
Drop reference to Fibre Channel port.
Definition: fc.h:315
A reference counter.
Definition: refcnt.h:26
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static void fc_peer_put(struct fc_peer *peer)
Drop reference to Fibre Channel peer.
Definition: fc.h:390
struct fc_peer * peer
Fibre Channel peer.
Definition: fcns.c:52
struct fc_port * port
Fibre Channel port.
Definition: fcns.c:54

References container_of, fc_peer_put(), fc_port_put(), free, fc_ns_query::peer, and fc_ns_query::port.

Referenced by fc_ns_query().

◆ fc_ns_query_close()

static void fc_ns_query_close ( struct fc_ns_query query,
int  rc 
)
static

Close name server query.

Parameters
queryName server query
rcReason for close

Definition at line 89 of file fcns.c.

89  {
90 
91  /* Stop process */
92  process_del ( &query->process );
93 
94  /* Shut down interfaces */
95  intf_shutdown ( &query->xchg, rc );
96 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:273
struct interface xchg
Fibre Channel exchange.
Definition: fcns.c:49
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
struct process process
Process.
Definition: fcns.c:57

References intf_shutdown(), fc_ns_query::process, process_del(), rc, and fc_ns_query::xchg.

Referenced by fc_ns_query_deliver(), and fc_ns_query_step().

◆ fc_ns_query_deliver()

static int fc_ns_query_deliver ( struct fc_ns_query query,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Receive name server query response.

Parameters
queryName server query
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 106 of file fcns.c.

108  {
109  union fc_ns_response *resp = iobuf->data;
110  struct fc_port_id *peer_port_id;
111  int rc;
112 
113  /* Sanity check */
114  if ( iob_len ( iobuf ) < sizeof ( resp->ct ) ) {
115  DBGC ( query, "FCNS %p received underlength response (%zd "
116  "bytes)\n", query, iob_len ( iobuf ) );
117  rc = -EINVAL;
118  goto done;
119  }
120 
121  /* Handle response */
122  switch ( ntohs ( resp->ct.code ) ) {
123  case FC_GS_ACCEPT:
124  if ( iob_len ( iobuf ) < sizeof ( resp->gid_pn ) ) {
125  DBGC ( query, "FCNS %p received underlength accept "
126  "response (%zd bytes)\n",
127  query, iob_len ( iobuf ) );
128  rc = -EINVAL;
129  goto done;
130  }
131  peer_port_id = &resp->gid_pn.port_id.port_id;
132  DBGC ( query, "FCNS %p resolved %s to %s via %s\n",
133  query, fc_ntoa ( &query->peer->port_wwn ),
134  fc_id_ntoa ( peer_port_id ), query->port->name );
135  if ( ( rc = query->done ( query->peer, query->port,
136  peer_port_id ) ) != 0 )
137  goto done;
138  break;
139  case FC_GS_REJECT:
140  DBGC ( query, "FCNS %p rejected (reason %02x explanation "
141  "%02x)\n", query, resp->reject.ct.reason,
142  resp->reject.ct.explanation );
143  break;
144  default:
145  DBGC ( query, "FCNS %p received invalid response code %04x\n",
146  query, ntohs ( resp->ct.code ) );
147  rc = -ENOTSUP;
148  goto done;
149  }
150 
151  rc = 0;
152  done:
153  free_iob ( iobuf );
154  fc_ns_query_close ( query, rc );
155  return rc;
156 }
struct fc_ct_header ct
Common Transport header.
Definition: fcns.h:191
#define EINVAL
Invalid argument.
Definition: errno.h:428
char name[8]
Name of this port.
Definition: fc.h:258
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * fc_id_ntoa(const struct fc_port_id *id)
Format Fibre Channel port ID.
Definition: fc.c:92
static void fc_ns_query_close(struct fc_ns_query *query, int rc)
Close name server query.
Definition: fcns.c:89
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define DBGC(...)
Definition: compiler.h:505
uint8_t reason
Reason code.
Definition: fcns.h:37
#define ntohs(value)
Definition: byteswap.h:136
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition: fc.c:127
uint16_t code
Command/response code.
Definition: fcns.h:31
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
struct fc_ct_header ct
Common Transport header.
Definition: fcns.h:205
struct fc_ns_gid_pn_response gid_pn
Get ID by port name.
Definition: fcns.h:209
struct fc_ns_reject_response reject
Rejection.
Definition: fcns.h:207
A Fibre Channel port identifier.
Definition: fc.h:37
int(* done)(struct fc_peer *peer, struct fc_port *port, struct fc_port_id *peer_port_id)
Success handler.
Definition: fcns.c:65
struct fc_port_id port_id
Port ID.
Definition: fcns.h:171
Rejected.
Definition: fcns.h:58
uint8_t explanation
Reason code explanation.
Definition: fcns.h:39
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
struct fc_name port_wwn
Port name.
Definition: fc.h:347
void * data
Start of data.
Definition: iobuf.h:44
struct fc_ns_port_id port_id
Port ID.
Definition: fcns.h:199
A Fibre Channel name server response.
Definition: fcns.h:203
Accepted.
Definition: fcns.h:56
struct fc_peer * peer
Fibre Channel peer.
Definition: fcns.c:52
struct fc_port * port
Fibre Channel port.
Definition: fcns.c:54
struct bofm_section_header done
Definition: bofm_test.c:46

References fc_ct_header::code, fc_ns_response::ct, fc_ns_reject_response::ct, io_buffer::data, DBGC, fc_ns_query::done, done, EINVAL, ENOTSUP, fc_ct_header::explanation, FC_GS_ACCEPT, FC_GS_REJECT, fc_id_ntoa(), fc_ns_query_close(), fc_ntoa(), free_iob(), fc_ns_response::gid_pn, iob_len(), fc_port::name, ntohs, fc_ns_query::peer, fc_ns_query::port, fc_ns_port_id::port_id, fc_ns_gid_pn_response::port_id, fc_peer::port_wwn, rc, fc_ct_header::reason, and fc_ns_response::reject.

◆ fc_ns_query_step()

static void fc_ns_query_step ( struct fc_ns_query query)
static

Name server query process.

Parameters
queryName server query

Definition at line 163 of file fcns.c.

163  {
164  struct xfer_metadata meta;
165  struct fc_ns_gid_pn_request gid_pn;
166  int xchg_id;
167  int rc;
168 
169  /* Create exchange */
170  if ( ( xchg_id = fc_xchg_originate ( &query->xchg, query->port,
171  &fc_gs_port_id,
172  FC_TYPE_CT ) ) < 0 ) {
173  rc = xchg_id;
174  DBGC ( query, "FCNS %p could not create exchange: %s\n",
175  query, strerror ( rc ) );
176  fc_ns_query_close ( query, rc );
177  return;
178  }
179 
180  /* Construct query request */
181  memset ( &gid_pn, 0, sizeof ( gid_pn ) );
182  gid_pn.ct.revision = FC_CT_REVISION;
183  gid_pn.ct.type = FC_GS_TYPE_DS;
184  gid_pn.ct.subtype = FC_DS_SUBTYPE_NAME;
185  gid_pn.ct.code = htons ( FC_NS_GET ( FC_NS_PORT_NAME, FC_NS_PORT_ID ));
186  memcpy ( &gid_pn.port_wwn, &query->peer->port_wwn,
187  sizeof ( gid_pn.port_wwn ) );
188  memset ( &meta, 0, sizeof ( meta ) );
189  meta.flags = XFER_FL_OVER;
190 
191  /* Send query */
192  if ( ( rc = xfer_deliver_raw_meta ( &query->xchg, &gid_pn,
193  sizeof ( gid_pn ), &meta ) ) != 0){
194  DBGC ( query, "FCNS %p could not deliver query: %s\n",
195  query, strerror ( rc ) );
196  fc_ns_query_close ( query, rc );
197  return;
198  }
199 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Data transfer metadata.
Definition: xfer.h:22
int fc_xchg_originate(struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id, unsigned int type)
Originate a new Fibre Channel exchange.
Definition: fc.c:728
struct interface xchg
Fibre Channel exchange.
Definition: fcns.c:49
int xfer_deliver_raw_meta(struct interface *intf, const void *data, size_t len, struct xfer_metadata *meta)
Deliver datagram as raw data.
Definition: xfer.c:267
static void fc_ns_query_close(struct fc_ns_query *query, int rc)
Close name server query.
Definition: fcns.c:89
A Fibre Channel name server GID_PN request.
Definition: fcns.h:175
Port name.
Definition: fcns.h:106
#define DBGC(...)
Definition: compiler.h:505
Name server.
Definition: fcns.h:88
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define FC_CT_REVISION
Fibre Channel Common Transport revision.
Definition: fcns.h:45
int meta(WINDOW *, bool)
Common Transport.
Definition: fc.h:194
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
Port ID.
Definition: fcns.h:104
Directory service.
Definition: fcns.h:50
struct fc_name port_wwn
Port name.
Definition: fc.h:347
Get.
Definition: fcns.h:94
#define XFER_FL_OVER
Sender is relinquishing use of half-duplex channel.
Definition: xfer.h:50
struct fc_port_id fc_gs_port_id
Generic services port ID.
Definition: fc.c:71
struct fc_peer * peer
Fibre Channel peer.
Definition: fcns.c:52
#define htons(value)
Definition: byteswap.h:135
struct fc_port * port
Fibre Channel port.
Definition: fcns.c:54
void * memset(void *dest, int character, size_t len) __nonnull

References fc_ct_header::code, fc_ns_gid_pn_request::ct, DBGC, FC_CT_REVISION, FC_DS_SUBTYPE_NAME, fc_gs_port_id, FC_GS_TYPE_DS, FC_NS_GET, FC_NS_PORT_ID, FC_NS_PORT_NAME, fc_ns_query_close(), FC_TYPE_CT, fc_xchg_originate(), htons, memcpy(), memset(), meta(), fc_ns_query::peer, fc_ns_query::port, fc_ns_gid_pn_request::port_wwn, fc_peer::port_wwn, rc, fc_ct_header::revision, strerror(), fc_ct_header::subtype, fc_ct_header::type, fc_ns_query::xchg, xfer_deliver_raw_meta(), and XFER_FL_OVER.

◆ fc_ns_query()

int fc_ns_query ( struct fc_peer peer,
struct fc_port port,
int(*)(struct fc_peer *peer, struct fc_port *port, struct fc_port_id *peer_port_id)  done 
)

Issue Fibre Channel name server query.

Parameters
peerFibre Channel peer
portFibre Channel port
Return values
rcReturn status code

Definition at line 222 of file fcns.c.

224  {
225  struct fc_ns_query *query;
226 
227  /* Allocate and initialise structure */
228  query = zalloc ( sizeof ( *query ) );
229  if ( ! query )
230  return -ENOMEM;
231  ref_init ( &query->refcnt, fc_ns_query_free );
232  intf_init ( &query->xchg, &fc_ns_query_xchg_desc, &query->refcnt );
234  &query->refcnt );
235  query->peer = fc_peer_get ( peer );
236  query->port = fc_port_get ( port );
237  query->done = done;
238 
239  DBGC ( query, "FCNS %p querying %s via %s\n",
240  query, fc_ntoa ( &query->peer->port_wwn ), port->name );
241 
242  /* Mortalise self and return */
243  ref_put ( &query->refcnt );
244  return 0;
245 }
static void fc_ns_query_free(struct refcnt *refcnt)
Free name server query.
Definition: fcns.c:74
struct interface xchg
Fibre Channel exchange.
Definition: fcns.c:49
A Fibre Channel name server query.
Definition: fcns.c:45
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition: process.h:161
#define DBGC(...)
Definition: compiler.h:505
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition: fc.c:127
static struct process_descriptor fc_ns_query_process_desc
Name server process descriptor.
Definition: fcns.c:212
struct refcnt refcnt
Reference count.
Definition: fcns.c:47
#define ENOMEM
Not enough space.
Definition: errno.h:534
u8 port
Port number.
Definition: CIB_PRM.h:31
int(* done)(struct fc_peer *peer, struct fc_port *port, struct fc_port_id *peer_port_id)
Success handler.
Definition: fcns.c:65
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct fc_name port_wwn
Port name.
Definition: fc.h:347
struct process process
Process.
Definition: fcns.c:57
static struct fc_peer * fc_peer_get(struct fc_peer *peer)
Get reference to Fibre Channel peer.
Definition: fc.h:379
static struct fc_port * fc_port_get(struct fc_port *port)
Get reference to Fibre Channel port.
Definition: fc.h:304
static struct interface_descriptor fc_ns_query_xchg_desc
Name server exchange interface descriptor.
Definition: fcns.c:208
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
struct fc_peer * peer
Fibre Channel peer.
Definition: fcns.c:52
struct bofm_section_header done
Definition: bofm_test.c:46
struct fc_port * port
Fibre Channel port.
Definition: fcns.c:54
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References DBGC, fc_ns_query::done, done, ENOMEM, fc_ns_query_free(), fc_ns_query_process_desc, fc_ns_query_xchg_desc, fc_ntoa(), fc_peer_get(), fc_port_get(), intf_init(), fc_ns_query::peer, port, fc_ns_query::port, fc_peer::port_wwn, fc_ns_query::process, process_init(), ref_init, ref_put, fc_ns_query::refcnt, fc_ns_query::xchg, and zalloc().

Variable Documentation

◆ fc_ns_query_xchg_op

struct interface_operation fc_ns_query_xchg_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
A Fibre Channel name server query.
Definition: fcns.c:45
static void fc_ns_query_close(struct fc_ns_query *query, int rc)
Close name server query.
Definition: fcns.c:89
static int fc_ns_query_deliver(struct fc_ns_query *query, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Receive name server query response.
Definition: fcns.c:106
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193

Name server exchange interface operations.

Definition at line 202 of file fcns.c.

◆ fc_ns_query_xchg_desc

struct interface_descriptor fc_ns_query_xchg_desc
static
Initial value:
=
struct interface xchg
Fibre Channel exchange.
Definition: fcns.c:49
A Fibre Channel name server query.
Definition: fcns.c:45
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:65
static struct interface_operation fc_ns_query_xchg_op[]
Name server exchange interface operations.
Definition: fcns.c:202

Name server exchange interface descriptor.

Definition at line 208 of file fcns.c.

Referenced by fc_ns_query().

◆ fc_ns_query_process_desc

struct process_descriptor fc_ns_query_process_desc
static
Initial value:
=
A process.
Definition: process.h:17
A Fibre Channel name server query.
Definition: fcns.c:45
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition: process.h:97
static void fc_ns_query_step(struct fc_ns_query *query)
Name server query process.
Definition: fcns.c:163

Name server process descriptor.

Definition at line 212 of file fcns.c.

Referenced by fc_ns_query().