iPXE
Data Structures | Defines | Functions | Variables
slam.c File Reference

Scalable Local Area Multicast protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/features.h>
#include <ipxe/iobuf.h>
#include <ipxe/bitmap.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/uri.h>
#include <ipxe/tcpip.h>
#include <ipxe/timer.h>
#include <ipxe/retry.h>

Go to the source code of this file.

Data Structures

struct  slam_request
 A SLAM request. More...

Defines

#define SLAM_DEFAULT_PORT   10000
 Default SLAM server port.
#define SLAM_DEFAULT_MULTICAST_IP   ( ( 239 << 24 ) | ( 255 << 16 ) | ( 1 << 8 ) | ( 1 << 0 ) )
 Default SLAM multicast IP address.
#define SLAM_DEFAULT_MULTICAST_PORT   10000
 Default SLAM multicast port.
#define SLAM_MAX_HEADER_LEN
 Maximum SLAM header length.
#define SLAM_MAX_BLOCKS_PER_NACK   4
 Maximum number of blocks to request per NACK.
#define SLAM_MAX_NACK_LEN   ( 7 /* block */ + 7 /* #blocks */ + 1 /* NUL */ )
 Maximum SLAM NACK length.
#define SLAM_SLAVE_TIMEOUT   ( 1 * TICKS_PER_SEC )
 SLAM slave timeout.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FEATURE (FEATURE_PROTOCOL,"SLAM", DHCP_EB_FEATURE_SLAM, 1)
static void slam_free (struct refcnt *refcnt)
 Free a SLAM request.
static void slam_finished (struct slam_request *slam, int rc)
 Mark SLAM request as complete.
static int slam_put_value (struct slam_request *slam, struct io_buffer *iobuf, unsigned long value)
 Add a variable-length value to a SLAM packet.
static int slam_tx_nack (struct slam_request *slam)
 Send SLAM NACK packet.
static void slam_master_timer_expired (struct retry_timer *timer, int fail)
 Handle SLAM master client retry timer expiry.
static void slam_slave_timer_expired (struct retry_timer *timer, int fail)
 Handle SLAM slave client retry timer expiry.
static int slam_pull_value (struct slam_request *slam, struct io_buffer *iobuf, unsigned long *value)
 Read and strip a variable-length value from a SLAM packet.
static int slam_pull_header (struct slam_request *slam, struct io_buffer *iobuf)
 Read and strip SLAM header.
static int slam_mc_socket_deliver (struct slam_request *slam, struct io_buffer *iobuf, struct xfer_metadata *rx_meta __unused)
 Receive SLAM data packet.
static int slam_socket_deliver (struct slam_request *slam, struct io_buffer *iobuf, struct xfer_metadata *rx_meta __unused)
 Receive SLAM non-data packet.
static int slam_parse_multicast_address (struct slam_request *slam, const char *path, struct sockaddr_in *address)
 Parse SLAM URI multicast address.
static int slam_open (struct interface *xfer, struct uri *uri)
 Initiate a SLAM request.

Variables

static struct interface_operation slam_socket_operations []
 SLAM unicast socket interface operations.
static struct interface_descriptor slam_socket_desc
 SLAM unicast socket interface descriptor.
static struct interface_operation slam_mc_socket_operations []
 SLAM multicast socket interface operations.
static struct interface_descriptor slam_mc_socket_desc
 SLAM multicast socket interface descriptor.
static struct interface_operation slam_xfer_operations []
 SLAM data transfer interface operations.
static struct interface_descriptor slam_xfer_desc
 SLAM data transfer interface descriptor.
struct uri_opener slam_uri_opener __uri_opener
 SLAM URI opener.

Detailed Description

Scalable Local Area Multicast protocol.

The SLAM protocol is supported only by Etherboot; it was designed and implemented by Eric Biederman. A server implementation is available in contrib/mini-slamd. There does not appear to be any documentation beyond a few sparse comments in Etherboot's proto_slam.c.

SLAM packets use three types of data field:

Nul : A single NUL (0) byte, used as a list terminator

Raw : A block of raw data

Int : A variable-length integer, in big-endian order. The length of the integer is encoded in the most significant three bits.

Packets received by the client have the following layout:

Int : Transaction identifier. This is an opaque value.

Int : Total number of bytes in the transfer.

Int : Block size, in bytes.

Int : Packet sequence number within the transfer (if this packet contains data).

Raw : Packet data (if this packet contains data).

Packets transmitted by the client consist of a run-length-encoded representation of the received-blocks bitmap, looking something like:

Int : Number of consecutive successfully-received packets Int : Number of consecutive missing packets Int : Number of consecutive successfully-received packets Int : Number of consecutive missing packets .... Nul

Definition in file slam.c.


Define Documentation

#define SLAM_DEFAULT_PORT   10000

Default SLAM server port.

Definition at line 91 of file slam.c.

Referenced by slam_open().

#define SLAM_DEFAULT_MULTICAST_IP   ( ( 239 << 24 ) | ( 255 << 16 ) | ( 1 << 8 ) | ( 1 << 0 ) )

Default SLAM multicast IP address.

Definition at line 94 of file slam.c.

Referenced by slam_open().

#define SLAM_DEFAULT_MULTICAST_PORT   10000

Default SLAM multicast port.

Definition at line 98 of file slam.c.

Referenced by slam_open().

Value:
( 7 /* transaction id */ + 7 /* total_bytes */ + \
                              7 /* block_size */ )

Maximum SLAM header length.

Definition at line 101 of file slam.c.

#define SLAM_MAX_BLOCKS_PER_NACK   4

Maximum number of blocks to request per NACK.

This is a policy decision equivalent to selecting a TCP window size.

Definition at line 109 of file slam.c.

Referenced by slam_tx_nack().

#define SLAM_MAX_NACK_LEN   ( 7 /* block */ + 7 /* #blocks */ + 1 /* NUL */ )

Maximum SLAM NACK length.

We only ever send a NACK for a single range of up to SLAM_MAX_BLOCKS_PER_NACK blocks.

Definition at line 116 of file slam.c.

Referenced by slam_tx_nack().

#define SLAM_SLAVE_TIMEOUT   ( 1 * TICKS_PER_SEC )

SLAM slave timeout.

Definition at line 119 of file slam.c.

Referenced by slam_mc_socket_deliver(), and slam_open().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
FEATURE ( FEATURE_PROTOCOL  ,
"SLAM"  ,
DHCP_EB_FEATURE_SLAM  ,
 
)
static void slam_free ( struct refcnt refcnt) [static]

Free a SLAM request.

Parameters:
refcntReference counter

Definition at line 159 of file slam.c.

References slam_request::bitmap, bitmap_free(), container_of, and free.

Referenced by slam_open().

                                                {
        struct slam_request *slam =
                container_of ( refcnt, struct slam_request, refcnt );

        bitmap_free ( &slam->bitmap );
        free ( slam );
}
static void slam_finished ( struct slam_request slam,
int  rc 
) [static]

Mark SLAM request as complete.

Parameters:
slamSLAM request
rcReturn status code

Definition at line 173 of file slam.c.

References DBGC, intf_shutdown(), slam_request::master_timer, slam_request::mc_socket, slam_request::nack_sent, slam_request::slave_timer, slam_request::socket, stop_timer(), strerror(), slam_request::xfer, and xfer_deliver_raw().

Referenced by slam_mc_socket_deliver(), slam_open(), slam_pull_header(), and slam_slave_timer_expired().

                                                                {
        static const uint8_t slam_disconnect[] = { 0 };

        DBGC ( slam, "SLAM %p finished with status code %d (%s)\n",
               slam, rc, strerror ( rc ) );

        /* Send a disconnect message if we ever sent anything to the
         * server.
         */
        if ( slam->nack_sent ) {
                xfer_deliver_raw ( &slam->socket, slam_disconnect,
                                   sizeof ( slam_disconnect ) );
        }

        /* Stop the retry timers */
        stop_timer ( &slam->master_timer );
        stop_timer ( &slam->slave_timer );

        /* Close all data transfer interfaces */
        intf_shutdown ( &slam->socket, rc );
        intf_shutdown ( &slam->mc_socket, rc );
        intf_shutdown ( &slam->xfer, rc );
}
static int slam_put_value ( struct slam_request slam,
struct io_buffer iobuf,
unsigned long  value 
) [static]

Add a variable-length value to a SLAM packet.

Parameters:
slamSLAM request
iobufI/O buffer
valueValue to add
Return values:
rcReturn status code

Adds a variable-length value to the end of an I/O buffer. Will always leave at least one byte of tailroom in the I/O buffer (to allow space for the terminating NUL).

Definition at line 215 of file slam.c.

References assert, data, DBGC2, ENOBUFS, flsl, iob_put, iob_tailroom(), len, and value.

Referenced by slam_tx_nack().

                                                                           {
        uint8_t *data;
        size_t len;
        unsigned int i;

        /* Calculate variable length required to store value.  Always
         * leave at least one byte in the I/O buffer.
         */
        len = ( ( flsl ( value ) + 10 ) / 8 );
        if ( len >= iob_tailroom ( iobuf ) ) {
                DBGC2 ( slam, "SLAM %p cannot add %zd-byte value\n",
                        slam, len );
                return -ENOBUFS;
        }
        /* There is no valid way within the protocol that we can end
         * up trying to push a full-sized long (i.e. without space for
         * the length encoding).
         */
        assert ( len <= sizeof ( value ) );

        /* Add value */
        data = iob_put ( iobuf, len );
        for ( i = len ; i-- ; ) {
                data[i] = value;
                value >>= 8;
        }
        *data |= ( len << 5 );
        assert ( value == 0 );

        return 0;
}
static int slam_tx_nack ( struct slam_request slam) [static]

Send SLAM NACK packet.

Parameters:
slamSLAM request
Return values:
rcReturn status code

Definition at line 254 of file slam.c.

References slam_request::bitmap, bitmap_first_gap(), bitmap_test(), DBGC, DBGCP, ENOMEM, free_iob(), iob_disown, iob_put, slam_request::nack_sent, slam_request::num_blocks, rc, SLAM_MAX_BLOCKS_PER_NACK, SLAM_MAX_NACK_LEN, slam_put_value(), slam_request::socket, xfer_alloc_iob(), and xfer_deliver_iob().

Referenced by slam_master_timer_expired(), slam_slave_timer_expired(), and slam_socket_deliver().

                                                      {
        struct io_buffer *iobuf;
        unsigned long first_block;
        unsigned long num_blocks;
        uint8_t *nul;
        int rc;

        /* Mark NACK as sent, so that we know we have to disconnect later */
        slam->nack_sent = 1;

        /* Allocate I/O buffer */
        iobuf = xfer_alloc_iob ( &slam->socket, SLAM_MAX_NACK_LEN );
        if ( ! iobuf ) {
                DBGC ( slam, "SLAM %p could not allocate I/O buffer\n",
                       slam );
                rc = -ENOMEM;
                goto err_alloc;
        }

        /* Construct NACK.  We always request only a single packet;
         * this allows us to force multicast-TFTP-style flow control
         * on the SLAM server, which will otherwise just blast the
         * data out as fast as it can.  On a gigabit network, without
         * RX checksumming, this would inevitably cause packet drops.
         */
        first_block = bitmap_first_gap ( &slam->bitmap );
        for ( num_blocks = 1 ; ; num_blocks++ ) {
                if ( num_blocks >= SLAM_MAX_BLOCKS_PER_NACK )
                        break;
                if ( ( first_block + num_blocks ) >= slam->num_blocks )
                        break;
                if ( bitmap_test ( &slam->bitmap,
                                   ( first_block + num_blocks ) ) )
                        break;
        }
        if ( first_block ) {
                DBGCP ( slam, "SLAM %p transmitting NACK for blocks "
                        "%ld-%ld\n", slam, first_block,
                        ( first_block + num_blocks - 1 ) );
        } else {
                DBGC ( slam, "SLAM %p transmitting initial NACK for blocks "
                       "0-%ld\n", slam, ( num_blocks - 1 ) );
        }
        if ( ( rc = slam_put_value ( slam, iobuf, first_block ) ) != 0 )
                goto err_put_value;
        if ( ( rc = slam_put_value ( slam, iobuf, num_blocks ) ) != 0 )
                goto err_put_value;
        nul = iob_put ( iobuf, 1 );
        *nul = 0;

        /* Transmit packet */
        return xfer_deliver_iob ( &slam->socket, iob_disown ( iobuf ) );

 err_put_value:
        free_iob ( iobuf );
 err_alloc:
        return rc;
}
static void slam_master_timer_expired ( struct retry_timer timer,
int  fail 
) [static]

Handle SLAM master client retry timer expiry.

Parameters:
timerMaster retry timer
failFailure indicator

Definition at line 319 of file slam.c.

References container_of, DBGC, slam_request::master_timer, slam_tx_nack(), and start_timer().

Referenced by slam_open().

                                                   {
        struct slam_request *slam =
                container_of ( timer, struct slam_request, master_timer );

        if ( fail ) {
                /* Allow timer to stop running.  We will terminate the
                 * connection only if the slave timer times out.
                 */
                DBGC ( slam, "SLAM %p giving up acting as master client\n",
                       slam );
        } else {
                /* Retransmit NACK */
                start_timer ( timer );
                slam_tx_nack ( slam );
        }
}
static void slam_slave_timer_expired ( struct retry_timer timer,
int  fail 
) [static]

Handle SLAM slave client retry timer expiry.

Parameters:
timerMaster retry timer
failFailure indicator

Definition at line 343 of file slam.c.

References container_of, DBGC, ETIMEDOUT, slam_finished(), slam_tx_nack(), slam_request::slave_timer, and start_timer().

Referenced by slam_open().

                                                   {
        struct slam_request *slam =
                container_of ( timer, struct slam_request, slave_timer );

        if ( fail ) {
                /* Terminate connection */
                slam_finished ( slam, -ETIMEDOUT );
        } else {
                /* Try sending a NACK */
                DBGC ( slam, "SLAM %p trying to become master client\n",
                       slam );
                start_timer ( timer );
                slam_tx_nack ( slam );
        }
}
static int slam_pull_value ( struct slam_request slam,
struct io_buffer iobuf,
unsigned long *  value 
) [static]

Read and strip a variable-length value from a SLAM packet.

Parameters:
slamSLAM request
iobufI/O buffer
valueValue to fill in, or NULL to ignore value
Return values:
rcReturn status code

Reads a variable-length value from the start of the I/O buffer.

Definition at line 376 of file slam.c.

References io_buffer::data, data, DBGC, EINVAL, iob_len(), iob_pull, and len.

Referenced by slam_mc_socket_deliver(), and slam_pull_header().

                                                    {
        uint8_t *data;
        size_t len;

        /* Sanity check */
        if ( iob_len ( iobuf ) == 0 ) {
                DBGC ( slam, "SLAM %p empty value\n", slam );
                return -EINVAL;
        }

        /* Read and verify length of value */
        data = iobuf->data;
        len = ( *data >> 5 );
        if ( ( len == 0 ) ||
             ( value && ( len > sizeof ( *value ) ) ) ) {
                DBGC ( slam, "SLAM %p invalid value length %zd bytes\n",
                       slam, len );
                return -EINVAL;
        }
        if ( len > iob_len ( iobuf ) ) {
                DBGC ( slam, "SLAM %p value extends beyond I/O buffer\n",
                       slam );
                return -EINVAL;
        }

        /* Strip value */
        iob_pull ( iobuf, len );

        /* Read value, if applicable */
        if ( value ) {
                *value = ( *data & 0x1f );
                while ( --len ) {
                        *value <<= 8;
                        *value |= *(++data);
                }
        }

        return 0;
}
static int slam_pull_header ( struct slam_request slam,
struct io_buffer iobuf 
) [static]

Read and strip SLAM header.

Parameters:
slamSLAM request
iobufI/O buffer
Return values:
rcReturn status code

Definition at line 425 of file slam.c.

References assert, slam_request::bitmap, bitmap_free(), bitmap_resize(), slam_request::block_size, io_buffer::data, DBGC, EINVAL, slam_request::header, header, slam_request::header_len, iob_len(), iob_pull, memcmp(), memcpy(), memset(), NULL, slam_request::num_blocks, rc, slam_finished(), slam_pull_value(), strerror(), slam_request::total_bytes, slam_request::xfer, and xfer_seek().

Referenced by slam_mc_socket_deliver(), and slam_socket_deliver().

                                                        {
        void *header = iobuf->data;
        unsigned long total_bytes;
        unsigned long block_size;
        int rc;

        /* If header matches cached header, just pull it and return */
        if ( ( slam->header_len <= iob_len ( iobuf ) ) &&
             ( memcmp ( slam->header, iobuf->data, slam->header_len ) == 0 )){
                iob_pull ( iobuf, slam->header_len );
                return 0;
        }

        DBGC ( slam, "SLAM %p detected changed header; resetting\n", slam );

        /* Read and strip transaction ID, total number of bytes, and
         * block size.
         */
        if ( ( rc = slam_pull_value ( slam, iobuf, NULL ) ) != 0 )
                return rc;
        if ( ( rc = slam_pull_value ( slam, iobuf, &total_bytes ) ) != 0 )
                return rc;
        if ( ( rc = slam_pull_value ( slam, iobuf, &block_size ) ) != 0 )
                return rc;

        /* Sanity check */
        if ( block_size == 0 ) {
                DBGC ( slam, "SLAM %p ignoring zero block size\n", slam );
                return -EINVAL;
        }

        /* Update the cached header */
        slam->header_len = ( iobuf->data - header );
        assert ( slam->header_len <= sizeof ( slam->header ) );
        memcpy ( slam->header, header, slam->header_len );

        /* Calculate number of blocks */
        slam->total_bytes = total_bytes;
        slam->block_size = block_size;
        slam->num_blocks = ( ( total_bytes + block_size - 1 ) / block_size );
        DBGC ( slam, "SLAM %p has total bytes %ld, block size %ld, num "
               "blocks %ld\n", slam, slam->total_bytes, slam->block_size,
               slam->num_blocks );

        /* Discard and reset the bitmap */
        bitmap_free ( &slam->bitmap );
        memset ( &slam->bitmap, 0, sizeof ( slam->bitmap ) );

        /* Allocate a new bitmap */
        if ( ( rc = bitmap_resize ( &slam->bitmap,
                                    slam->num_blocks ) ) != 0 ) {
                /* Failure to allocate a bitmap is fatal */
                DBGC ( slam, "SLAM %p could not allocate bitmap for %ld "
                       "blocks: %s\n", slam, slam->num_blocks,
                       strerror ( rc ) );
                slam_finished ( slam, rc );
                return rc;
        }

        /* Notify recipient of file size */
        xfer_seek ( &slam->xfer, slam->total_bytes );

        return 0;
}
static int slam_mc_socket_deliver ( struct slam_request slam,
struct io_buffer iobuf,
struct xfer_metadata *rx_meta  __unused 
) [static]

Receive SLAM data packet.

Parameters:
slamSLAM request
iobufI/O buffer
Return values:
rcReturn status code

Definition at line 498 of file slam.c.

References slam_request::bitmap, bitmap_full(), bitmap_set(), bitmap_test(), slam_request::block_size, DBGC, EINVAL, xfer_metadata::flags, free_iob(), iob_len(), len, slam_request::master_timer, memset(), slam_request::num_blocks, xfer_metadata::offset, rc, slam_finished(), slam_pull_header(), slam_pull_value(), SLAM_SLAVE_TIMEOUT, slam_request::slave_timer, start_timer_fixed(), stop_timer(), slam_request::xfer, xfer_deliver(), and XFER_FL_ABS_OFFSET.

                                                                             {
        struct xfer_metadata meta;
        unsigned long packet;
        size_t len;
        int rc;

        /* Stop the master client timer.  Restart the slave client timer. */
        stop_timer ( &slam->master_timer );
        stop_timer ( &slam->slave_timer );
        start_timer_fixed ( &slam->slave_timer, SLAM_SLAVE_TIMEOUT );

        /* Read and strip packet header */
        if ( ( rc = slam_pull_header ( slam, iobuf ) ) != 0 )
                goto err_discard;

        /* Read and strip packet number */
        if ( ( rc = slam_pull_value ( slam, iobuf, &packet ) ) != 0 )
                goto err_discard;

        /* Sanity check packet number */
        if ( packet >= slam->num_blocks ) {
                DBGC ( slam, "SLAM %p received out-of-range packet %ld "
                       "(num_blocks=%ld)\n", slam, packet, slam->num_blocks );
                rc = -EINVAL;
                goto err_discard;
        }

        /* Sanity check length */
        len = iob_len ( iobuf );
        if ( len > slam->block_size ) {
                DBGC ( slam, "SLAM %p received oversize packet of %zd bytes "
                       "(block_size=%ld)\n", slam, len, slam->block_size );
                rc = -EINVAL;
                goto err_discard;
        }
        if ( ( packet != ( slam->num_blocks - 1 ) ) &&
             ( len < slam->block_size ) ) {
                DBGC ( slam, "SLAM %p received short packet of %zd bytes "
                       "(block_size=%ld)\n", slam, len, slam->block_size );
                rc = -EINVAL;
                goto err_discard;
        }

        /* If we have already seen this packet, discard it */
        if ( bitmap_test ( &slam->bitmap, packet ) ) {
                goto discard;
        }

        /* Pass to recipient */
        memset ( &meta, 0, sizeof ( meta ) );
        meta.flags = XFER_FL_ABS_OFFSET;
        meta.offset = ( packet * slam->block_size );
        if ( ( rc = xfer_deliver ( &slam->xfer, iobuf, &meta ) ) != 0 )
                goto err;

        /* Mark block as received */
        bitmap_set ( &slam->bitmap, packet );

        /* If we have received all blocks, terminate */
        if ( bitmap_full ( &slam->bitmap ) )
                slam_finished ( slam, 0 );

        return 0;

 err_discard:
 discard:
        free_iob ( iobuf );
 err:
        return rc;
}
static int slam_socket_deliver ( struct slam_request slam,
struct io_buffer iobuf,
struct xfer_metadata *rx_meta  __unused 
) [static]

Receive SLAM non-data packet.

Parameters:
slamSLAM request
iobufI/O buffer
Return values:
rcReturn status code

Definition at line 578 of file slam.c.

References io_buffer::data, DBGC, DBGC_HD, EINVAL, free_iob(), iob_len(), slam_request::master_timer, rc, slam_pull_header(), slam_tx_nack(), start_timer(), and stop_timer().

                                                                          {
        int rc;

        /* Restart the master client timer */
        stop_timer ( &slam->master_timer );
        start_timer ( &slam->master_timer );

        /* Read and strip packet header */
        if ( ( rc = slam_pull_header ( slam, iobuf ) ) != 0 )
                goto discard;

        /* Sanity check */
        if ( iob_len ( iobuf ) != 0 ) {
                DBGC ( slam, "SLAM %p received trailing garbage:\n", slam );
                DBGC_HD ( slam, iobuf->data, iob_len ( iobuf ) );
                rc = -EINVAL;
                goto discard;
        }

        /* Discard packet */
        free_iob ( iobuf );

        /* Send NACK in reply */
        slam_tx_nack ( slam );

        return 0;

 discard:
        free_iob ( iobuf );
        return rc;

}
static int slam_parse_multicast_address ( struct slam_request slam,
const char *  path,
struct sockaddr_in address 
) [static]

Parse SLAM URI multicast address.

Parameters:
slamSLAM request
pathPath portion of x-slam:// URI
addressSocket address to fill in
Return values:
rcReturn status code

Definition at line 656 of file slam.c.

References assert, DBGC, EINVAL, end, htons, inet_aton(), memcpy(), sockaddr_in::sin_addr, sockaddr_in::sin_port, strchr(), strlen(), and strtoul().

Referenced by slam_open().

                                                                        {
        char path_dup[ strlen ( path ) /* no +1 */ ];
        char *sep;
        char *end;

        /* Create temporary copy of path, minus the leading '/' */
        assert ( *path == '/' );
        memcpy ( path_dup, ( path + 1 ) , sizeof ( path_dup ) );

        /* Parse port, if present */
        sep = strchr ( path_dup, ':' );
        if ( sep ) {
                *(sep++) = '\0';
                address->sin_port = htons ( strtoul ( sep, &end, 0 ) );
                if ( *end != '\0' ) {
                        DBGC ( slam, "SLAM %p invalid multicast port "
                               "\"%s\"\n", slam, sep );
                        return -EINVAL;
                }
        }

        /* Parse address */
        if ( inet_aton ( path_dup, &address->sin_addr ) == 0 ) {
                DBGC ( slam, "SLAM %p invalid multicast address \"%s\"\n",
                       slam, path_dup );
                return -EINVAL;
        }

        return 0;
}
static int slam_open ( struct interface xfer,
struct uri uri 
) [static]

Initiate a SLAM request.

Parameters:
xferData transfer interface
uriUniform Resource Identifier
Return values:
rcReturn status code

Definition at line 696 of file slam.c.

References AF_INET, slam_request::bitmap, bitmap_resize(), DBGC, EINVAL, ENOMEM, slam_request::header_len, uri::host, htonl, htons, intf_init(), intf_plug_plug(), slam_request::master_timer, slam_request::mc_socket, memcpy(), memset(), NULL, slam_request::num_blocks, uri::path, rc, ref_init, ref_put, slam_request::refcnt, sockaddr_in::sin_family, SLAM_DEFAULT_MULTICAST_IP, SLAM_DEFAULT_MULTICAST_PORT, SLAM_DEFAULT_PORT, slam_finished(), slam_free(), slam_master_timer_expired(), slam_parse_multicast_address(), SLAM_SLAVE_TIMEOUT, slam_slave_timer_expired(), slam_request::slave_timer, SOCK_DGRAM, slam_request::socket, sockaddr_tcpip::st_port, start_timer_fixed(), strerror(), uri_port(), slam_request::xfer, xfer_open_named_socket(), xfer_open_socket(), and zalloc().

                                                                 {
        static const struct sockaddr_in default_multicast = {
                .sin_family = AF_INET,
                .sin_port = htons ( SLAM_DEFAULT_MULTICAST_PORT ),
                .sin_addr = { htonl ( SLAM_DEFAULT_MULTICAST_IP ) },
        };
        struct slam_request *slam;
        struct sockaddr_tcpip server;
        struct sockaddr_in multicast;
        int rc;

        /* Sanity checks */
        if ( ! uri->host )
                return -EINVAL;

        /* Allocate and populate structure */
        slam = zalloc ( sizeof ( *slam ) );
        if ( ! slam )
                return -ENOMEM;
        ref_init ( &slam->refcnt, slam_free );
        intf_init ( &slam->xfer, &slam_xfer_desc, &slam->refcnt );
        intf_init ( &slam->socket, &slam_socket_desc, &slam->refcnt );
        intf_init ( &slam->mc_socket, &slam_mc_socket_desc, &slam->refcnt );
        timer_init ( &slam->master_timer, slam_master_timer_expired,
                     &slam->refcnt );
        timer_init ( &slam->slave_timer, slam_slave_timer_expired,
                     &slam->refcnt );
        /* Fake an invalid cached header of { 0x00, ... } */
        slam->header_len = 1;
        /* Fake parameters for initial NACK */
        slam->num_blocks = 1;
        if ( ( rc = bitmap_resize ( &slam->bitmap, 1 ) ) != 0 ) {
                DBGC ( slam, "SLAM %p could not allocate initial bitmap: "
                       "%s\n", slam, strerror ( rc ) );
                goto err;
        }

        /* Open unicast socket */
        memset ( &server, 0, sizeof ( server ) );
        server.st_port = htons ( uri_port ( uri, SLAM_DEFAULT_PORT ) );
        if ( ( rc = xfer_open_named_socket ( &slam->socket, SOCK_DGRAM,
                                             ( struct sockaddr * ) &server,
                                             uri->host, NULL ) ) != 0 ) {
                DBGC ( slam, "SLAM %p could not open unicast socket: %s\n",
                       slam, strerror ( rc ) );
                goto err;
        }

        /* Open multicast socket */
        memcpy ( &multicast, &default_multicast, sizeof ( multicast ) );
        if ( uri->path &&
             ( ( rc = slam_parse_multicast_address ( slam, uri->path,
                                                     &multicast ) ) != 0 ) ) {
                goto err;
        }
        if ( ( rc = xfer_open_socket ( &slam->mc_socket, SOCK_DGRAM,
                                 ( struct sockaddr * ) &multicast,
                                 ( struct sockaddr * ) &multicast ) ) != 0 ) {
                DBGC ( slam, "SLAM %p could not open multicast socket: %s\n",
                       slam, strerror ( rc ) );
                goto err;
        }

        /* Start slave retry timer */
        start_timer_fixed ( &slam->slave_timer, SLAM_SLAVE_TIMEOUT );

        /* Attach to parent interface, mortalise self, and return */
        intf_plug_plug ( &slam->xfer, xfer );
        ref_put ( &slam->refcnt );
        return 0;

 err:
        slam_finished ( slam, rc );
        ref_put ( &slam->refcnt );
        return rc;
}

Variable Documentation

Initial value:

SLAM unicast socket interface operations.

Definition at line 614 of file slam.c.

Initial value:

SLAM unicast socket interface descriptor.

Definition at line 620 of file slam.c.

Initial value:

SLAM multicast socket interface operations.

Definition at line 624 of file slam.c.

Initial value:

SLAM multicast socket interface descriptor.

Definition at line 630 of file slam.c.

Initial value:

SLAM data transfer interface operations.

Definition at line 640 of file slam.c.

Initial value:

SLAM data transfer interface descriptor.

Definition at line 645 of file slam.c.

struct uri_opener slam_uri_opener __uri_opener
Initial value:
 {
        .scheme = "x-slam",
        .open   = slam_open,
}

SLAM URI opener.

Definition at line 774 of file slam.c.