iPXE
Data Structures | Defines | 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...

Defines

#define PEERDIST_DISCOVERY_PORT   3702
 PeerDist discovery port.
#define PEERDIST_DISCOVERY_IPV4   ( ( 239 << 24 ) | ( 255 << 16 ) | ( 255 << 8 ) | ( 250 << 0 ) )
 PeerDist discovery IPv4 address (239.255.255.250)
#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)

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.
int peerdist_discovery_reply (char *data, size_t len, struct peerdist_discovery_reply *reply)
 Parse discovery reply.

Variables

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

Detailed Description

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

Definition in file pccrd.h.


Define Documentation

#define PEERDIST_DISCOVERY_PORT   3702

PeerDist discovery port.

Definition at line 13 of file pccrd.h.

#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.

#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 ( GPL2_OR_LATER_OR_UBDL  )
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.

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

Referenced by peerdisc_socket_tx().

                                                                       {
        char *request;
        int len;

        /* Construct request */
        len = asprintf ( &request, PEERDIST_DISCOVERY_REQUEST, uuid, id );
        if ( len < 0 )
                return NULL;

        return request;
}
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.

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

                                                                        {
        static const struct peerdist_discovery_block_count zcount = {
                .hex = "00000000",
        };
        struct peerdist_discovery_block_count *count;
        unsigned int max;
        unsigned int i;
        char *scopes;
        char *xaddrs;
        char *blockcount;
        char *in;
        char *out;
        size_t skip;

        /* Find <wsd:Scopes> tag */
        scopes = peerdist_discovery_reply_values ( data, len, "wsd:Scopes" );
        if ( ! scopes ) {
                DBGC ( reply, "PCCRD %p missing <wsd:Scopes> tag\n", reply );
                return -ENOENT;
        }

        /* Find <wsd:XAddrs> tag */
        xaddrs = peerdist_discovery_reply_values ( data, len, "wsd:XAddrs" );
        if ( ! xaddrs ) {
                DBGC ( reply, "PCCRD %p missing <wsd:XAddrs> tag\n", reply );
                return -ENOENT;
        }

        /* Find <PeerDist:BlockCount> tag */
        blockcount = peerdist_discovery_reply_values ( data, len,
                                                       "PeerDist:BlockCount" );
        if ( ! blockcount ) {
                DBGC ( reply, "PCCRD %p missing <PeerDist:BlockCount> tag\n",
                       reply );
                return -ENOENT;
        }

        /* Determine maximum number of segments (according to number
         * of entries in the block count list).
         */
        max = ( strlen ( blockcount ) / sizeof ( *count ) );
        count = container_of ( blockcount,
                               struct peerdist_discovery_block_count, hex[0] );

        /* Eliminate any segments with a zero block count */
        for ( i = 0, in = scopes, out = scopes ; *in ; i++, in += skip ) {

                /* Fail if we have overrun the maximum number of segments */
                if ( i >= max ) {
                        DBGC ( reply, "PCCRD %p too many segment IDs\n",
                               reply );
                        return -EPROTO;
                }

                /* Delete segment if block count is zero */
                skip = ( strlen ( in ) + 1 /* NUL */ );
                if ( memcmp ( count[i].hex, zcount.hex,
                              sizeof ( zcount.hex ) ) == 0 )
                        continue;
                strcpy ( out, in );
                out += skip;
        }
        out[0] = '\0'; /* Ensure list is terminated with a zero-length string */

        /* Fill in discovery reply */
        reply->ids = scopes;
        reply->locations = xaddrs;

        return 0;
}

Variable Documentation

char hex[8]

Count (as an eight-digit hex value)

Definition at line 29 of file pccrd.h.

Referenced by peerdist_discovery_reply(), and vcprintf().