Commit c422f1bd authored by Allan Stephens's avatar Allan Stephens Committed by Paul Gortmaker

tipc: Simplify enforcement of reserved name type prohibition

Streamlines the logic that prevents an application from binding a
reserved TIPC name type to a port by moving the check to the code
that handles a socket bind() operation. This allows internal TIPC
subsystems to bind a reserved name without having to set an atomic
flag to gain permission to use such a name. (This simplification is
now possible due to the elimination of support for TIPC's native API.)
Signed-off-by: default avatarAllan Stephens <allan.stephens@windriver.com>
Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
parent c74a4611
...@@ -481,7 +481,7 @@ int tipc_cfg_init(void) ...@@ -481,7 +481,7 @@ int tipc_cfg_init(void)
seq.type = TIPC_CFG_SRV; seq.type = TIPC_CFG_SRV;
seq.lower = seq.upper = tipc_own_addr; seq.lower = seq.upper = tipc_own_addr;
res = tipc_nametbl_publish_rsv(config_port_ref, TIPC_ZONE_SCOPE, &seq); res = tipc_publish(config_port_ref, TIPC_ZONE_SCOPE, &seq);
if (res) if (res)
goto failed; goto failed;
......
...@@ -114,10 +114,8 @@ struct name_table { ...@@ -114,10 +114,8 @@ struct name_table {
}; };
static struct name_table table; static struct name_table table;
static atomic_t rsv_publ_ok = ATOMIC_INIT(0);
DEFINE_RWLOCK(tipc_nametbl_lock); DEFINE_RWLOCK(tipc_nametbl_lock);
static int hash(int x) static int hash(int x)
{ {
return x & (tipc_nametbl_size - 1); return x & (tipc_nametbl_size - 1);
...@@ -665,22 +663,7 @@ int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, ...@@ -665,22 +663,7 @@ int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit,
return res; return res;
} }
/** /*
* tipc_nametbl_publish_rsv - publish port name using a reserved name type
*/
int tipc_nametbl_publish_rsv(u32 ref, unsigned int scope,
struct tipc_name_seq const *seq)
{
int res;
atomic_inc(&rsv_publ_ok);
res = tipc_publish(ref, scope, seq);
atomic_dec(&rsv_publ_ok);
return res;
}
/**
* tipc_nametbl_publish - add name publication to network name tables * tipc_nametbl_publish - add name publication to network name tables
*/ */
...@@ -694,11 +677,6 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, ...@@ -694,11 +677,6 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
tipc_max_publications); tipc_max_publications);
return NULL; return NULL;
} }
if ((type < TIPC_RESERVED_TYPES) && !atomic_read(&rsv_publ_ok)) {
warn("Publication failed, reserved name {%u,%u,%u}\n",
type, lower, upper);
return NULL;
}
write_lock_bh(&tipc_nametbl_lock); write_lock_bh(&tipc_nametbl_lock);
table.local_publ_count++; table.local_publ_count++;
......
...@@ -91,8 +91,6 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space); ...@@ -91,8 +91,6 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space);
u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *node); u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *node);
int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit,
struct tipc_port_list *dports); struct tipc_port_list *dports);
int tipc_nametbl_publish_rsv(u32 ref, unsigned int scope,
struct tipc_name_seq const *seq);
struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
u32 scope, u32 port_ref, u32 key); u32 scope, u32 port_ref, u32 key);
int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key); int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key);
......
...@@ -355,6 +355,9 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) ...@@ -355,6 +355,9 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
else if (addr->addrtype != TIPC_ADDR_NAMESEQ) else if (addr->addrtype != TIPC_ADDR_NAMESEQ)
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
if (addr->addr.nameseq.type < TIPC_RESERVED_TYPES)
return -EACCES;
return (addr->scope > 0) ? return (addr->scope > 0) ?
tipc_publish(portref, addr->scope, &addr->addr.nameseq) : tipc_publish(portref, addr->scope, &addr->addr.nameseq) :
tipc_withdraw(portref, -addr->scope, &addr->addr.nameseq); tipc_withdraw(portref, -addr->scope, &addr->addr.nameseq);
......
...@@ -552,7 +552,7 @@ int tipc_subscr_start(void) ...@@ -552,7 +552,7 @@ int tipc_subscr_start(void)
if (res) if (res)
goto failed; goto failed;
res = tipc_nametbl_publish_rsv(topsrv.setup_port, TIPC_NODE_SCOPE, &seq); res = tipc_publish(topsrv.setup_port, TIPC_NODE_SCOPE, &seq);
if (res) { if (res) {
tipc_deleteport(topsrv.setup_port); tipc_deleteport(topsrv.setup_port);
topsrv.setup_port = 0; topsrv.setup_port = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment