1 /******************************************************************************
3 Copyright (c) 2012, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
34 * an endpoint implementation of 802.1Q-2011 MRP (MMRP, MVRP, MSRP)
37 /* Operating specific defines */
40 typedef int socklen_t;
42 #define snprintf _snprintf
44 size_t mrpd_send(SOCKET sockfd, const void *buf, size_t len, int flags);
45 #elif defined __linux__
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
52 #define INVALID_SOCKET -1
53 #define SOCKET_ERROR -1
54 #define closesocket(s) close(s);
55 #define mrpd_send send
59 #define __STDC_CONSTANT_MACROS
65 #include <stdint.h> // for uint8_t etc
67 typedef struct eth_hdr {
74 * NumberOfValues is the number of EVENTS encoded in the various
75 * 3/4 PACK Bytes. Non-multiples of (3) [ for 3-packed ] or (4)
76 * [ for 4-packed ] indicates the trailing events are transmitted
77 * as -0- and should be ignored (and NOT interpreted as an ENDMARK)
78 * A value of -0- indicates there are no events to report (a NULL).
80 * furthermore, the events are 'vector' operations - the first encoded event
81 * operates on the (FirstEvent) attribute, the second encoded event
82 * operates on the (FirstEvent+1) attribute, and so forth.
84 typedef struct mrpdu_message {
85 uint8_t AttributeType;
86 uint8_t AttributeLength; /* length of FirstValue */
89 * parsing of the data field is application specific - either
90 * a ushort with an attribute list length followed by vector
91 * attributes, or just a list of vector attributes ...
94 /* table should have a trailing NULL (0x0000) indicating the ENDMARK */
97 typedef struct mrpdu {
98 uint8_t ProtocolVersion;
99 /* Microsoft does not support embedded arrays of 0 length
100 * mrpdu_message_t MessageList[];
101 * mrpdu should have trailing NULL (0x0000) indicating the ENDMARK */
104 #define MRPD_GET_MRPDU_MESSAGE_LIST(a) ((unsigned char *)&((a)->ProtocolVersion) + 1)
105 #define MRPD_OFFSETOF_MRPD_GET_MRPDU_MESSAGE_LIST (1)
107 #define MAX_FRAME_SIZE 2000
108 #define MRPD_PORT_DEFAULT 7500
109 #define MAX_MRPD_CMDSZ (1500)
111 /* forward declare */
114 int mrpd_init_timers(struct mrp_database *mrp_db);
115 int mrpd_timer_start(HTIMER timerfd, unsigned long value_ms);
116 int mrpd_timer_stop(HTIMER timerfd);
117 int mrpd_send_ctl_msg(struct sockaddr_in *client_addr, char *notify_data,
119 int mrpd_init_protocol_socket(uint16_t etype, SOCKET * sock,
120 unsigned char *multicast_addr);
121 int mrpd_close_socket(SOCKET sock);
122 int mrpd_recvmsgbuf(SOCKET sock, char **buf);