iPXE
Data Structures | Macros | Functions | Variables
pccrd.h File Reference

Peer Content Caching and Retrieval: Discovery Protocol [MS-PCCRD]. More...

Go to the source code of this file.

Data Structures

struct  peerdist_discovery_block_count
 A PeerDist discovery reply block count. More...
 
struct  peerdist_discovery_reply
 A PeerDist discovery reply. More...
 

Macros

#define PEERDIST_DISCOVERY_PORT   3702
 PeerDist discovery port. More...
 
#define PEERDIST_DISCOVERY_IPV4   ( ( 239 << 24 ) | ( 255 << 16 ) | ( 255 << 8 ) | ( 250 << 0 ) )
 PeerDist discovery IPv4 address (239.255.255.250) More...
 
#define PEERDIST_DISCOVERY_IPV6   { 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xc }
 PeerDist discovery IPv6 address (ff02::c) More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct peerdist_discovery_block_count __attribute__ ((packed))
 
char * peerdist_discovery_request (const char *uuid, const char *id)
 Construct discovery request. More...
 
int peerdist_discovery_reply (char *data, size_t len, struct peerdist_discovery_reply *reply)
 Parse discovery reply. More...
 

Variables

char hex [8]
 Count (as an eight-digit hex value) More...
 
struct peerdist_discovery_reply __attribute__
 

Detailed Description

Peer Content Caching and Retrieval: Discovery Protocol [MS-PCCRD].

Definition in file pccrd.h.

Macro Definition Documentation

◆ PEERDIST_DISCOVERY_PORT

#define PEERDIST_DISCOVERY_PORT   3702

PeerDist discovery port.

Definition at line 13 of file pccrd.h.

◆ PEERDIST_DISCOVERY_IPV4

#define PEERDIST_DISCOVERY_IPV4   ( ( 239 << 24 ) | ( 255 << 16 ) | ( 255 << 8 ) | ( 250 << 0 ) )

PeerDist discovery IPv4 address (239.255.255.250)

Definition at line 16 of file pccrd.h.

◆ PEERDIST_DISCOVERY_IPV6

#define PEERDIST_DISCOVERY_IPV6   { 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xc }

PeerDist discovery IPv6 address (ff02::c)

Definition at line 20 of file pccrd.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

◆ peerdist_discovery_request()

char* peerdist_discovery_request ( const char *  uuid,
const char *  id 
)

Construct discovery request.

Parameters
uuidMessage UUID string
idSegment identifier string
Return values
requestDiscovery request, or NULL on failure

The request is dynamically allocated; the caller must eventually free() the request.

Definition at line 106 of file pccrd.c.

106  {
107  char *request;
108  int len;
109 
110  /* Construct request */
112  if ( len < 0 )
113  return NULL;
114 
115  return request;
116 }
#define PEERDIST_DISCOVERY_REQUEST
Discovery request format.
Definition: pccrd.c:64
A universally unique ID.
Definition: uuid.h:15
int asprintf(char **strp, const char *fmt,...)
Write a formatted string to newly allocated memory.
Definition: asprintf.c:41
uint32_t len
Length.
Definition: ena.h:14
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References asprintf(), len, NULL, PEERDIST_DISCOVERY_REQUEST, and request.

Referenced by peerdisc_socket_tx().

◆ peerdist_discovery_reply()

int peerdist_discovery_reply ( char *  data,
size_t  len,
struct peerdist_discovery_reply reply 
)

Parse discovery reply.

Parameters
dataReply data (not NUL-terminated, will be modified)
lenLength of reply data
replyDiscovery reply to fill in
Return values
rcReturn status code

The discovery reply includes pointers to strings within the modified reply data.

Definition at line 216 of file pccrd.c.

217  {
218  static const struct peerdist_discovery_block_count zcount = {
219  .hex = "00000000",
220  };
222  unsigned int max;
223  unsigned int i;
224  char *scopes;
225  char *xaddrs;
226  char *blockcount;
227  char *in;
228  char *out;
229  size_t skip;
230 
231  /* Find <wsd:Scopes> tag */
232  scopes = peerdist_discovery_reply_values ( data, len, "wsd:Scopes" );
233  if ( ! scopes ) {
234  DBGC ( reply, "PCCRD %p missing <wsd:Scopes> tag\n", reply );
235  return -ENOENT;
236  }
237 
238  /* Find <wsd:XAddrs> tag */
239  xaddrs = peerdist_discovery_reply_values ( data, len, "wsd:XAddrs" );
240  if ( ! xaddrs ) {
241  DBGC ( reply, "PCCRD %p missing <wsd:XAddrs> tag\n", reply );
242  return -ENOENT;
243  }
244 
245  /* Find <PeerDist:BlockCount> tag */
246  blockcount = peerdist_discovery_reply_values ( data, len,
247  "PeerDist:BlockCount" );
248  if ( ! blockcount ) {
249  DBGC ( reply, "PCCRD %p missing <PeerDist:BlockCount> tag\n",
250  reply );
251  return -ENOENT;
252  }
253 
254  /* Determine maximum number of segments (according to number
255  * of entries in the block count list).
256  */
257  max = ( strlen ( blockcount ) / sizeof ( *count ) );
258  count = container_of ( blockcount,
259  struct peerdist_discovery_block_count, hex[0] );
260 
261  /* Eliminate any segments with a zero block count */
262  for ( i = 0, in = scopes, out = scopes ; *in ; i++, in += skip ) {
263 
264  /* Fail if we have overrun the maximum number of segments */
265  if ( i >= max ) {
266  DBGC ( reply, "PCCRD %p too many segment IDs\n",
267  reply );
268  return -EPROTO;
269  }
270 
271  /* Delete segment if block count is zero */
272  skip = ( strlen ( in ) + 1 /* NUL */ );
273  if ( memcmp ( count[i].hex, zcount.hex,
274  sizeof ( zcount.hex ) ) == 0 )
275  continue;
276  strcpy ( out, in );
277  out += skip;
278  }
279  out[0] = '\0'; /* Ensure list is terminated with a zero-length string */
280 
281  /* Fill in discovery reply */
282  reply->ids = scopes;
283  reply->locations = xaddrs;
284 
285  return 0;
286 }
A PeerDist discovery reply block count.
Definition: pccrd.h:24
#define max(x, y)
Definition: ath.h:39
__be32 in[4]
Definition: CIB_PRM.h:35
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
char hex[8]
Count (as an eight-digit hex value)
Definition: pccrd.h:12
__be32 out[4]
Definition: CIB_PRM.h:36
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:326
char * locations
List of peer locations.
Definition: pccrd.h:40
#define EPROTO
Protocol error.
Definition: errno.h:624
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
char hex[8]
Count (as an eight-digit hex value)
Definition: pccrd.h:26
char * ids
List of segment ID strings.
Definition: pccrd.h:35
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
static char * peerdist_discovery_reply_values(char *data, size_t len, const char *name)
Locate discovery reply values.
Definition: pccrd.c:157

References container_of, count, data, DBGC, ENOENT, EPROTO, hex, peerdist_discovery_block_count::hex, peerdist_discovery_reply::ids, in, len, peerdist_discovery_reply::locations, max, memcmp(), out, peerdist_discovery_reply_values(), strcpy(), and strlen().

Variable Documentation

◆ hex

char hex[8]

Count (as an eight-digit hex value)

Definition at line 12 of file pccrd.h.

Referenced by peerdist_discovery_reply(), and vcprintf().

◆ __attribute__