91 #define SLAM_DEFAULT_PORT 10000 94 #define SLAM_DEFAULT_MULTICAST_IP \ 95 ( ( 239 << 24 ) | ( 255 << 16 ) | ( 1 << 8 ) | ( 1 << 0 ) ) 98 #define SLAM_DEFAULT_MULTICAST_PORT 10000 101 #define SLAM_MAX_HEADER_LEN ( 7 + 7 + \ 109 #define SLAM_MAX_BLOCKS_PER_NACK 4 116 #define SLAM_MAX_NACK_LEN ( 7 + 7 + 1 ) 119 #define SLAM_SLAVE_TIMEOUT ( 1 * TICKS_PER_SEC ) 174 static const uint8_t slam_disconnect[] = { 0 };
176 DBGC ( slam,
"SLAM %p finished with status code %d (%s)\n",
184 sizeof ( slam_disconnect ) );
226 DBGC2 ( slam,
"SLAM %p cannot add %zd-byte value\n",
238 for ( i =
len ; i-- ; ) {
256 unsigned long first_block;
257 unsigned long num_blocks;
267 DBGC ( slam,
"SLAM %p could not allocate I/O buffer\n",
280 for ( num_blocks = 1 ; ; num_blocks++ ) {
283 if ( ( first_block + num_blocks ) >= slam->
num_blocks )
286 ( first_block + num_blocks ) ) )
290 DBGCP ( slam,
"SLAM %p transmitting NACK for blocks " 291 "%ld-%ld\n", slam, first_block,
292 ( first_block + num_blocks - 1 ) );
294 DBGC ( slam,
"SLAM %p transmitting initial NACK for blocks " 295 "0-%ld\n", slam, ( num_blocks - 1 ) );
328 DBGC ( slam,
"SLAM %p giving up acting as master client\n",
353 DBGC ( slam,
"SLAM %p trying to become master client\n",
378 unsigned long *
value ) {
383 if (
iob_len ( iobuf ) == 0 ) {
384 DBGC ( slam,
"SLAM %p empty value\n", slam );
392 (
value && (
len >
sizeof ( *value ) ) ) ) {
393 DBGC ( slam,
"SLAM %p invalid value length %zd bytes\n",
398 DBGC ( slam,
"SLAM %p value extends beyond I/O buffer\n",
439 DBGC ( slam,
"SLAM %p detected changed header; resetting\n", slam );
453 DBGC ( slam,
"SLAM %p ignoring zero block size\n", slam );
466 DBGC ( slam,
"SLAM %p has total bytes %ld, block size %ld, num " 478 DBGC ( slam,
"SLAM %p could not allocate bitmap for %ld " 502 unsigned long packet;
521 DBGC ( slam,
"SLAM %p received out-of-range packet %ld " 522 "(num_blocks=%ld)\n", slam, packet, slam->
num_blocks );
530 DBGC ( slam,
"SLAM %p received oversize packet of %zd bytes " 535 if ( ( packet != ( slam->
num_blocks - 1 ) ) &&
537 DBGC ( slam,
"SLAM %p received short packet of %zd bytes " 592 if (
iob_len ( iobuf ) != 0 ) {
593 DBGC ( slam,
"SLAM %p received trailing garbage:\n", slam );
666 path_dup =
strdup ( path + 1 );
673 sep =
strchr ( path_dup,
':' );
677 if ( *
end !=
'\0' ) {
678 DBGC ( slam,
"SLAM %p invalid multicast port " 679 "\"%s\"\n", slam, sep );
687 DBGC ( slam,
"SLAM %p invalid multicast address \"%s\"\n",
711 static const struct sockaddr_in default_multicast = {
726 slam =
zalloc (
sizeof ( *slam ) );
742 DBGC ( slam,
"SLAM %p could not allocate initial bitmap: " 748 memset ( &server, 0,
sizeof ( server ) );
753 DBGC ( slam,
"SLAM %p could not open unicast socket: %s\n",
759 memcpy ( &multicast, &default_multicast,
sizeof ( multicast ) );
762 &multicast ) ) != 0 ) ) {
767 (
struct sockaddr * ) &multicast ) ) != 0 ) {
768 DBGC ( slam,
"SLAM %p could not open multicast socket: %s\n",
#define iob_pull(iobuf, len)
#define EINVAL
Invalid argument.
An object interface operation.
size_t header_len
Size of cached header.
struct arbelprm_rc_send_wqe rc
void intf_close(struct interface *intf, int rc)
Close an object interface.
#define iob_put(iobuf, len)
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
struct refcnt refcnt
Reference counter.
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
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.
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
static struct interface_operation slam_socket_operations[]
SLAM unicast socket interface operations.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define FEATURE_PROTOCOL
Network protocols.
static void bitmap_free(struct bitmap *bitmap)
Free bitmap resources.
static struct interface_descriptor slam_xfer_desc
SLAM data transfer interface descriptor.
uint8_t header[SLAM_MAX_HEADER_LEN]
Cached header.
#define XFER_FL_ABS_OFFSET
Offset is absolute.
#define ref_init(refcnt, free)
Initialise a reference counter.
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
uint64_t address
Base address.
static int slam_socket_deliver(struct slam_request *slam, struct io_buffer *iobuf, struct xfer_metadata *rx_meta __unused)
Receive SLAM non-data packet.
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
struct uri_opener slam_uri_opener __uri_opener
SLAM URI opener.
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Uniform Resource Identifiers.
int sock_aton(const char *string, struct sockaddr *sa)
Parse socket address.
sa_family_t sin_family
Socket address family (part of struct sockaddr)
int xfer_deliver_raw(struct interface *intf, const void *data, size_t len)
Deliver datagram as raw data without metadata.
int nack_sent
NACK sent flag.
Data transfer interfaces.
int bitmap_test(struct bitmap *bitmap, unsigned int bit)
Test bit in bitmap.
#define ENOMEM
Not enough space.
#define iob_disown(iobuf)
Disown an I/O buffer.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
#define SLAM_DEFAULT_PORT
Default SLAM server port.
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.
pseudo_bit_t value[0x00020]
#define __unused
Declare a variable or data structure as unused.
const char * path
Path (after URI decoding)
unsigned long block_size
Transfer block size.
static int slam_open(struct interface *xfer, struct uri *uri)
Initiate a SLAM request.
const char * scheme
URI protocol name.
static struct interface_operation slam_xfer_operations[]
SLAM data transfer interface operations.
Transport-network layer interface.
static int slam_pull_header(struct slam_request *slam, struct io_buffer *iobuf)
Read and strip SLAM header.
int bitmap_resize(struct bitmap *bitmap, unsigned int new_length)
Resize bitmap.
static struct interface_descriptor slam_socket_desc
SLAM unicast socket interface descriptor.
struct retry_timer master_timer
Master client retry timer.
int xfer_seek(struct interface *intf, off_t offset)
Seek to position.
unsigned long num_blocks
Number of blocks in transfer.
static struct interface_descriptor slam_mc_socket_desc
SLAM multicast socket interface descriptor.
uint16_t st_port
TCP/IP port.
Generalized socket address structure.
An object interface descriptor.
#define SLAM_DEFAULT_MULTICAST_PORT
Default SLAM multicast port.
struct interface socket
Unicast socket.
char * strerror(int errno)
Retrieve string representation of error number.
static void(* free)(struct refcnt *refcnt))
void * zalloc(size_t size)
Allocate cleared memory.
char * strchr(const char *src, int character)
Find character within a string.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
char * strdup(const char *src)
Duplicate string.
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Data transfer interface opening.
struct interface mc_socket
Multicast socket.
#define SLAM_DEFAULT_MULTICAST_IP
Default SLAM multicast IP address.
static void slam_master_timer_expired(struct retry_timer *timer, int fail)
Handle SLAM master client retry timer expiry.
const char * host
Host name.
void bitmap_set(struct bitmap *bitmap, unsigned int bit)
Set bit in bitmap.
void start_timer(struct retry_timer *timer)
Start timer.
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
#define DHCP_EB_FEATURE_SLAM
SLAM protocol.
static void slam_slave_timer_expired(struct retry_timer *timer, int fail)
Handle SLAM slave client retry timer expiry.
#define SLAM_MAX_BLOCKS_PER_NACK
Maximum number of blocks to request per NACK.
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
void stop_timer(struct retry_timer *timer)
Stop timer.
Bitmaps for multicast downloads.
static void slam_finished(struct slam_request *slam, int rc)
Mark SLAM request as complete.
struct interface xfer
Data transfer interface.
#define ENOBUFS
No buffer space available.
#define SLAM_MAX_NACK_LEN
Maximum SLAM NACK length.
FEATURE(FEATURE_PROTOCOL, "SLAM", DHCP_EB_FEATURE_SLAM, 1)
void * data
Start of data.
#define SLAM_SLAVE_TIMEOUT
SLAM slave timeout.
struct ena_aq_header header
Header.
unsigned int uri_port(const struct uri *uri, unsigned int default_port)
Get port from URI.
uint32_t end
Ending offset.
uint8_t data[48]
Additional event data.
static unsigned int bitmap_first_gap(struct bitmap *bitmap)
Get first gap within bitmap.
#define SLAM_MAX_HEADER_LEN
Maximum SLAM header length.
A Uniform Resource Identifier.
static int slam_parse_multicast_address(struct slam_request *slam, const char *path, struct sockaddr_tcpip *address)
Parse SLAM URI multicast address.
#define flsl(x)
Find last (i.e.
static int slam_mc_socket_deliver(struct slam_request *slam, struct io_buffer *iobuf, struct xfer_metadata *rx_meta __unused)
Receive SLAM data packet.
struct bitmap bitmap
Block bitmap.
static void slam_free(struct refcnt *refcnt)
Free a SLAM request.
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
static struct interface_operation slam_mc_socket_operations[]
SLAM multicast socket interface operations.
static int bitmap_full(struct bitmap *bitmap)
Check to see if bitmap is full.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
struct retry_timer slave_timer
Slave client retry timer.
unsigned long total_bytes
Total number of bytes in transfer.
#define NULL
NULL pointer (VOID *)
#define ETIMEDOUT
Connection timed out.
static int slam_tx_nack(struct slam_request *slam)
Send SLAM NACK packet.
#define AF_INET
IPv4 Internet addresses.
int xfer_open_named_socket(struct interface *xfer, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
Open named socket.
#define ref_put(refcnt)
Drop reference to object.
void * memset(void *dest, int character, size_t len) __nonnull