Skip to content

Commit 8aeb89f

Browse files
kaberdavem330
authored andcommitted
tipc: move bcast_addr from struct tipc_media to struct tipc_bearer
Some network protocols, like InfiniBand, don't have a fixed broadcast address but one that depends on the configuration. Move the bcast_addr to struct tipc_bearer and initialize it with the broadcast address of the network device when the bearer is enabled. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ccc4ba2 commit 8aeb89f

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

net/tipc/bcast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,10 @@ static int tipc_bcbearer_send(struct sk_buff *buf,
620620
continue; /* bearer pair doesn't add anything */
621621

622622
if (!tipc_bearer_blocked(p))
623-
tipc_bearer_send(p, buf, &p->media->bcast_addr);
623+
tipc_bearer_send(p, buf, &p->bcast_addr);
624624
else if (s && !tipc_bearer_blocked(s))
625625
/* unable to send on primary bearer */
626-
tipc_bearer_send(s, buf, &s->media->bcast_addr);
626+
tipc_bearer_send(s, buf, &s->bcast_addr);
627627
else
628628
/* unable to send on either bearer */
629629
continue;

net/tipc/bearer.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ int tipc_register_media(struct tipc_media *m_ptr)
8989

9090
if ((strlen(m_ptr->name) + 1) > TIPC_MAX_MEDIA_NAME)
9191
goto exit;
92-
if ((m_ptr->bcast_addr.media_id != m_ptr->type_id) ||
93-
!m_ptr->bcast_addr.broadcast)
94-
goto exit;
9592
if (m_ptr->priority > TIPC_MAX_LINK_PRI)
9693
goto exit;
9794
if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
@@ -407,7 +404,7 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
407404
INIT_LIST_HEAD(&b_ptr->links);
408405
spin_lock_init(&b_ptr->lock);
409406

410-
res = tipc_disc_create(b_ptr, &m_ptr->bcast_addr, disc_domain);
407+
res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr, disc_domain);
411408
if (res) {
412409
bearer_disable(b_ptr);
413410
pr_warn("Bearer <%s> rejected, discovery object creation failed\n",

net/tipc/bearer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ struct tipc_media {
9494
void (*disable_bearer)(struct tipc_bearer *b_ptr);
9595
int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size);
9696
int (*addr2msg)(struct tipc_media_addr *a, char *msg_area);
97-
int (*msg2addr)(struct tipc_media_addr *a, char *msg_area);
98-
struct tipc_media_addr bcast_addr;
97+
int (*msg2addr)(const struct tipc_bearer *b_ptr,
98+
struct tipc_media_addr *a, char *msg_area);
9999
u32 priority;
100100
u32 tolerance;
101101
u32 window;
@@ -134,6 +134,7 @@ struct tipc_bearer {
134134
char name[TIPC_MAX_BEARER_NAME];
135135
spinlock_t lock;
136136
struct tipc_media *media;
137+
struct tipc_media_addr bcast_addr;
137138
u32 priority;
138139
u32 window;
139140
u32 tolerance;

net/tipc/discover.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
129129
int link_fully_up;
130130

131131
media_addr.broadcast = 1;
132-
b_ptr->media->msg2addr(&media_addr, msg_media_addr(msg));
132+
b_ptr->media->msg2addr(b_ptr, &media_addr, msg_media_addr(msg));
133133
kfree_skb(buf);
134134

135135
/* Ensure message from node is valid and communication is permitted */

net/tipc/eth_media.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ static struct notifier_block notifier = {
7777
* Media-dependent "value" field stores MAC address in first 6 bytes
7878
* and zeroes out the remaining bytes.
7979
*/
80-
static void eth_media_addr_set(struct tipc_media_addr *a, char *mac)
80+
static void eth_media_addr_set(const struct tipc_bearer *tb_ptr,
81+
struct tipc_media_addr *a, char *mac)
8182
{
8283
memcpy(a->value, mac, ETH_ALEN);
8384
memset(a->value + ETH_ALEN, 0, sizeof(a->value) - ETH_ALEN);
8485
a->media_id = TIPC_MEDIA_TYPE_ETH;
85-
a->broadcast = !memcmp(mac, eth_media_info.bcast_addr.value, ETH_ALEN);
86+
a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, ETH_ALEN);
8687
}
8788

8889
/**
@@ -201,9 +202,13 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
201202
/* Associate TIPC bearer with Ethernet bearer */
202203
eb_ptr->bearer = tb_ptr;
203204
tb_ptr->usr_handle = (void *)eb_ptr;
205+
memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value));
206+
memcpy(tb_ptr->bcast_addr.value, dev->broadcast, ETH_ALEN);
207+
tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_ETH;
208+
tb_ptr->bcast_addr.broadcast = 1;
204209
tb_ptr->mtu = dev->mtu;
205210
tb_ptr->blocked = 0;
206-
eth_media_addr_set(&tb_ptr->addr, (char *)dev->dev_addr);
211+
eth_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr);
207212
return 0;
208213
}
209214

@@ -315,12 +320,13 @@ static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area)
315320
/**
316321
* eth_str2addr - convert message header address format to Ethernet format
317322
*/
318-
static int eth_msg2addr(struct tipc_media_addr *a, char *msg_area)
323+
static int eth_msg2addr(const struct tipc_bearer *tb_ptr,
324+
struct tipc_media_addr *a, char *msg_area)
319325
{
320326
if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH)
321327
return 1;
322328

323-
eth_media_addr_set(a, msg_area + ETH_ADDR_OFFSET);
329+
eth_media_addr_set(tb_ptr, a, msg_area + ETH_ADDR_OFFSET);
324330
return 0;
325331
}
326332

@@ -334,8 +340,6 @@ static struct tipc_media eth_media_info = {
334340
.addr2str = eth_addr2str,
335341
.addr2msg = eth_addr2msg,
336342
.msg2addr = eth_msg2addr,
337-
.bcast_addr = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
338-
TIPC_MEDIA_TYPE_ETH, 1 },
339343
.priority = TIPC_DEF_LINK_PRI,
340344
.tolerance = TIPC_DEF_LINK_TOL,
341345
.window = TIPC_DEF_LINK_WIN,

0 commit comments

Comments
 (0)