Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * net/tipc/eth_media.c: Ethernet bearer support for TIPC
0003  *
0004  * Copyright (c) 2001-2007, 2013-2014, Ericsson AB
0005  * Copyright (c) 2005-2008, 2011-2013, Wind River Systems
0006  * All rights reserved.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions are met:
0010  *
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  * 3. Neither the names of the copyright holders nor the names of its
0017  *    contributors may be used to endorse or promote products derived from
0018  *    this software without specific prior written permission.
0019  *
0020  * Alternatively, this software may be distributed under the terms of the
0021  * GNU General Public License ("GPL") version 2 as published by the Free
0022  * Software Foundation.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include "core.h"
0038 #include "bearer.h"
0039 
0040 /* Convert Ethernet address (media address format) to string */
0041 static int tipc_eth_addr2str(struct tipc_media_addr *addr,
0042                  char *strbuf, int bufsz)
0043 {
0044     if (bufsz < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */
0045         return 1;
0046 
0047     sprintf(strbuf, "%pM", addr->value);
0048     return 0;
0049 }
0050 
0051 /* Convert from media address format to discovery message addr format */
0052 static int tipc_eth_addr2msg(char *msg, struct tipc_media_addr *addr)
0053 {
0054     memset(msg, 0, TIPC_MEDIA_INFO_SIZE);
0055     msg[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH;
0056     memcpy(msg + TIPC_MEDIA_ADDR_OFFSET, addr->value, ETH_ALEN);
0057     return 0;
0058 }
0059 
0060 /* Convert raw mac address format to media addr format */
0061 static int tipc_eth_raw2addr(struct tipc_bearer *b,
0062                  struct tipc_media_addr *addr,
0063                  const char *msg)
0064 {
0065     memset(addr, 0, sizeof(*addr));
0066     ether_addr_copy(addr->value, msg);
0067     addr->media_id = TIPC_MEDIA_TYPE_ETH;
0068     addr->broadcast = is_broadcast_ether_addr(addr->value);
0069     return 0;
0070 }
0071 
0072 /* Convert discovery msg addr format to Ethernet media addr format */
0073 static int tipc_eth_msg2addr(struct tipc_bearer *b,
0074                  struct tipc_media_addr *addr,
0075                  char *msg)
0076 {
0077     /* Skip past preamble: */
0078     msg += TIPC_MEDIA_ADDR_OFFSET;
0079     return tipc_eth_raw2addr(b, addr, msg);
0080 }
0081 
0082 /* Ethernet media registration info */
0083 struct tipc_media eth_media_info = {
0084     .send_msg   = tipc_l2_send_msg,
0085     .enable_media   = tipc_enable_l2_media,
0086     .disable_media  = tipc_disable_l2_media,
0087     .addr2str   = tipc_eth_addr2str,
0088     .addr2msg   = tipc_eth_addr2msg,
0089     .msg2addr   = tipc_eth_msg2addr,
0090     .raw2addr   = tipc_eth_raw2addr,
0091     .priority   = TIPC_DEF_LINK_PRI,
0092     .tolerance  = TIPC_DEF_LINK_TOL,
0093     .min_win    = TIPC_DEF_LINK_WIN,
0094     .max_win    = TIPC_MAX_LINK_WIN,
0095     .type_id    = TIPC_MEDIA_TYPE_ETH,
0096     .hwaddr_len = ETH_ALEN,
0097     .name       = "eth"
0098 };