From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, allan.stephens@windriver.com,
ying.xue@windriver.com,
Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [PATCH net-next 08/23] tipc: Hide media-specific addressing details from generic bearer code
Date: Tue, 27 Dec 2011 12:39:27 -0500 [thread overview]
Message-ID: <1325007582-31610-9-git-send-email-paul.gortmaker@windriver.com> (raw)
In-Reply-To: <1325007582-31610-1-git-send-email-paul.gortmaker@windriver.com>
From: Allan Stephens <allan.stephens@windriver.com>
Reworks TIPC's media address data structure and associated processing
routines to transfer all media-specific details of address conversion
to the associated TIPC media adaptation code. TIPC's generic bearer code
now only needs to know which media type an address is associated with
and whether or not it is a broadcast address, and totally ignores the
"value" field that contains the actual media-specific addressing info.
These changes eliminate the need for a number of endianness conversion
operations and will make it easier for TIPC to support new media types
in the future.
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
net/tipc/bearer.c | 14 ++++++--------
net/tipc/bearer.h | 17 ++++++++---------
net/tipc/discover.c | 4 ++--
net/tipc/eth_media.c | 22 +++++++++++++---------
net/tipc/msg.c | 9 ++++++---
net/tipc/msg.h | 16 ++++++----------
6 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 17652f2..aa37261 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -108,7 +108,8 @@ int tipc_register_media(struct media *m_ptr)
if (!media_name_valid(m_ptr->name))
goto exit;
- if (m_ptr->bcast_addr.type != htonl(m_ptr->type_id))
+ if ((m_ptr->bcast_addr.media_id != m_ptr->type_id) ||
+ !m_ptr->bcast_addr.broadcast)
goto exit;
if (m_ptr->priority > TIPC_MAX_LINK_PRI)
goto exit;
@@ -138,20 +139,17 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
{
char addr_str[MAX_ADDR_STR];
struct media *m_ptr;
- u32 media_type;
- media_type = ntohl(a->type);
- m_ptr = media_find_id(media_type);
+ m_ptr = media_find_id(a->media_id);
if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str)))
tipc_printf(pb, "%s(%s)", m_ptr->name, addr_str);
else {
- unchar *addr = (unchar *)&a->dev_addr;
u32 i;
- tipc_printf(pb, "UNKNOWN(%u)", media_type);
- for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++)
- tipc_printf(pb, "-%02x", addr[i]);
+ tipc_printf(pb, "UNKNOWN(%u)", a->media_id);
+ for (i = 0; i < sizeof(a->value); i++)
+ tipc_printf(pb, "-%02x", a->value[i]);
}
}
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index 41a61d2..54a5a57 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -59,17 +59,16 @@
#define TIPC_MEDIA_TYPE_ETH 1
/*
- * Destination address structure used by TIPC bearers when sending messages
- *
- * IMPORTANT: The fields of this structure MUST be stored using the specified
- * byte order indicated below, as the structure is exchanged between nodes
- * as part of a link setup process.
+ * struct tipc_media_addr - destination address used by TIPC bearers
+ * @value: address info (format defined by media)
+ * @media_id: TIPC media type identifier
+ * @broadcast: non-zero if address is a broadcast address
*/
+
struct tipc_media_addr {
- __be32 type; /* bearer type (network byte order) */
- union {
- __u8 eth_addr[6]; /* 48 bit Ethernet addr (byte array) */
- } dev_addr;
+ u8 value[TIPC_MEDIA_ADDR_SIZE];
+ u8 media_id;
+ u8 broadcast;
};
struct tipc_bearer;
diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index f2fb96e..1ea2d44 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -84,7 +84,7 @@ static struct sk_buff *tipc_disc_init_msg(u32 type,
msg_set_non_seq(msg, 1);
msg_set_dest_domain(msg, dest_domain);
msg_set_bc_netid(msg, tipc_net_id);
- msg_set_media_addr(msg, &b_ptr->addr);
+ b_ptr->media->addr2msg(&b_ptr->addr, msg_media_addr(msg));
}
return buf;
}
@@ -130,7 +130,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
u32 type = msg_type(msg);
int link_fully_up;
- msg_get_media_addr(msg, &media_addr);
+ b_ptr->media->msg2addr(&media_addr, msg_media_addr(msg));
buf_discard(buf);
/* Validate discovery message from requesting node */
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index ebba0fc..3b75c0d 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -54,18 +54,24 @@ struct eth_bearer {
struct packet_type tipc_packet_type;
};
+static struct media eth_media_info;
static struct eth_bearer eth_bearers[MAX_ETH_BEARERS];
static int eth_started;
static struct notifier_block notifier;
/**
* eth_media_addr_set - initialize Ethernet media address structure
+ *
+ * Media-dependent "value" field stores MAC address in first 6 bytes
+ * and zeroes out the remaining bytes.
*/
static void eth_media_addr_set(struct tipc_media_addr *a, char *mac)
{
- a->type = htonl(TIPC_MEDIA_TYPE_ETH);
- memcpy(&a->dev_addr.eth_addr, mac, ETH_ALEN);
+ memcpy(a->value, mac, ETH_ALEN);
+ memset(a->value + ETH_ALEN, 0, sizeof(a->value) - ETH_ALEN);
+ a->media_id = TIPC_MEDIA_TYPE_ETH;
+ a->broadcast = !memcmp(mac, eth_media_info.bcast_addr.value, ETH_ALEN);
}
/**
@@ -94,7 +100,7 @@ static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr,
skb_reset_network_header(clone);
clone->dev = dev;
- dev_hard_header(clone, dev, ETH_P_TIPC, &dest->dev_addr.eth_addr,
+ dev_hard_header(clone, dev, ETH_P_TIPC, dest->value,
dev->dev_addr, clone->len);
dev_queue_xmit(clone);
return 0;
@@ -256,12 +262,10 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,
static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
{
- unchar *addr = (unchar *)&a->dev_addr;
-
if (str_size < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */
return 1;
- sprintf(str_buf, "%pM", addr);
+ sprintf(str_buf, "%pM", a->value);
return 0;
}
@@ -293,7 +297,7 @@ static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area)
{
memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE);
msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH;
- memcpy(msg_area + ETH_ADDR_OFFSET, a->dev_addr.eth_addr, ETH_ALEN);
+ memcpy(msg_area + ETH_ADDR_OFFSET, a->value, ETH_ALEN);
return 0;
}
@@ -322,8 +326,8 @@ static struct media eth_media_info = {
.str2addr = eth_str2addr,
.addr2msg = eth_addr2msg,
.msg2addr = eth_msg2addr,
- .bcast_addr = { htonl(TIPC_MEDIA_TYPE_ETH),
- { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} } },
+ .bcast_addr = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
+ TIPC_MEDIA_TYPE_ETH, 1 },
.priority = TIPC_DEF_LINK_PRI,
.tolerance = TIPC_DEF_LINK_TOL,
.window = TIPC_DEF_LINK_WIN,
diff --git a/net/tipc/msg.c b/net/tipc/msg.c
index 83d5096..3e4d3e2 100644
--- a/net/tipc/msg.c
+++ b/net/tipc/msg.c
@@ -333,11 +333,14 @@ void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str)
}
if (msg_user(msg) == LINK_CONFIG) {
- u32 *raw = (u32 *)msg;
- struct tipc_media_addr *orig = (struct tipc_media_addr *)&raw[5];
+ struct tipc_media_addr orig;
+
tipc_printf(buf, ":DDOM(%x):", msg_dest_domain(msg));
tipc_printf(buf, ":NETID(%u):", msg_bc_netid(msg));
- tipc_media_addr_printf(buf, orig);
+ memcpy(orig.value, msg_media_addr(msg), sizeof(orig.value));
+ orig.media_id = 0;
+ orig.broadcast = 0;
+ tipc_media_addr_printf(buf, &orig);
}
if (msg_user(msg) == BCAST_PROTOCOL) {
tipc_printf(buf, "BCNACK:AFTER(%u):", msg_bcgap_after(msg));
diff --git a/net/tipc/msg.h b/net/tipc/msg.h
index d93178f..7b0cda1 100644
--- a/net/tipc/msg.h
+++ b/net/tipc/msg.h
@@ -78,6 +78,8 @@
#define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE)
+#define TIPC_MEDIA_ADDR_OFFSET 5
+
struct tipc_msg {
__be32 hdr[15];
@@ -682,6 +684,10 @@ static inline void msg_set_redundant_link(struct tipc_msg *m, u32 r)
msg_set_bits(m, 5, 12, 0x1, r);
}
+static inline char *msg_media_addr(struct tipc_msg *m)
+{
+ return (char *)&m->hdr[TIPC_MEDIA_ADDR_OFFSET];
+}
/*
* Word 9
@@ -734,14 +740,4 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
u32 num_sect, unsigned int total_len,
int max_size, int usrmem, struct sk_buff **buf);
-static inline void msg_set_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
-{
- memcpy(&((int *)m)[5], a, sizeof(*a));
-}
-
-static inline void msg_get_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
-{
- memcpy(a, &((int *)m)[5], sizeof(*a));
-}
-
#endif
--
1.7.4.4
next prev parent reply other threads:[~2011-12-27 17:40 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-27 17:39 [PATCH net-next 00/23] TIPC: Updates for what will be v3.3 Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 01/23] tipc: Enable use by containers having their own network namespace Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 02/23] tipc: Register new media using pre-compiled structure Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 03/23] tipc: Optimize detection of duplicate media registration Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 04/23] tipc: Eliminate duplication of media structures Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 05/23] tipc: Streamline media registration error checking Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 06/23] tipc: Improve handling of media address printing errors Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 07/23] tipc: Add new address conversion routines for Ethernet media Paul Gortmaker
2011-12-27 17:39 ` Paul Gortmaker [this message]
2011-12-27 17:39 ` [PATCH net-next 09/23] tipc: Ignore neighbor discovery messages containing invalid address Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 10/23] tipc: Allow run-time alteration of default link settings Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 11/23] tipc: Revise comment justifying release of configuration spinlock Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 12/23] tipc: Minor optimization to deactivation of Ethernet media suppot Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 13/23] tipc: Do timely cleanup of disabled Ethernet bearer resources Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 14/23] tipc: Eliminate useless memset operations in Ethernet media support Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 15/23] tipc: Minor correction to TIPC module unloading Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 16/23] tipc: Eliminate useless check when network address is assigned Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 17/23] tipc: Eliminate dynamic allocation of broadcast link data structures Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 18/23] tipc: Ensure broadcast link spinlock is held when updating node map Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 19/23] tipc: Handle broadcast attempt when no neighboring nodes exist Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 20/23] tipc: Minor optimization of broadcast link transmit queue statistic Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 21/23] tipc: Flush unsent broadcast messages when contact with last node is lost Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 22/23] tipc: Ignore broadcast acknowledgements that are out-of-range Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 23/23] tipc: Allow use of buf_seqno() helper routine by unicast links Paul Gortmaker
2011-12-27 18:08 ` [PATCH net-next 00/23] TIPC: Updates for what will be v3.3 David Miller
2011-12-28 2:16 ` Paul Gortmaker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1325007582-31610-9-git-send-email-paul.gortmaker@windriver.com \
--to=paul.gortmaker@windriver.com \
--cc=allan.stephens@windriver.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=ying.xue@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).