diff options
author | Ying Xue <ying.xue@windriver.com> | 2013-06-17 10:54:41 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-06-17 18:53:00 -0400 |
commit | 7d0ab17b74330e39a68ba33099ccda27f794f519 (patch) | |
tree | 67eafce0b9ed65649be0407f800227001f3e5c54 /net/tipc | |
parent | 13a2e89873506d64d7e52f17b571da371a3e25a4 (diff) |
tipc: convert configuration server to use new server facility
As the new socket-based TIPC server infrastructure has been
introduced, we can now convert the configuration server to use
it. Then we can take future steps to simplify the configuration
server locking policy.
Some minor reordering of initialization is done, due to the
dependency on having tipc_socket_init completed.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/config.c | 102 | ||||
-rw-r--r-- | net/tipc/core.c | 4 | ||||
-rw-r--r-- | net/tipc/socket.c | 3 |
3 files changed, 49 insertions, 60 deletions
diff --git a/net/tipc/config.c b/net/tipc/config.c index f67866c765dd..4887ae04f3a5 100644 --- a/net/tipc/config.c +++ b/net/tipc/config.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * net/tipc/config.c: TIPC configuration management code | 2 | * net/tipc/config.c: TIPC configuration management code |
3 | * | 3 | * |
4 | * Copyright (c) 2002-2006, Ericsson AB | 4 | * Copyright (c) 2002-2006, Ericsson AB |
5 | * Copyright (c) 2004-2007, 2010-2012, Wind River Systems | 5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -38,12 +38,12 @@ | |||
38 | #include "port.h" | 38 | #include "port.h" |
39 | #include "name_table.h" | 39 | #include "name_table.h" |
40 | #include "config.h" | 40 | #include "config.h" |
41 | #include "server.h" | ||
41 | 42 | ||
42 | #define REPLY_TRUNCATED "<truncated>\n" | 43 | #define REPLY_TRUNCATED "<truncated>\n" |
43 | 44 | ||
44 | static u32 config_port_ref; | ||
45 | |||
46 | static DEFINE_SPINLOCK(config_lock); | 45 | static DEFINE_SPINLOCK(config_lock); |
46 | static struct tipc_server cfgsrv; | ||
47 | 47 | ||
48 | static const void *req_tlv_area; /* request message TLV area */ | 48 | static const void *req_tlv_area; /* request message TLV area */ |
49 | static int req_tlv_space; /* request message TLV area size */ | 49 | static int req_tlv_space; /* request message TLV area size */ |
@@ -381,33 +381,27 @@ exit: | |||
381 | return rep_tlv_buf; | 381 | return rep_tlv_buf; |
382 | } | 382 | } |
383 | 383 | ||
384 | static void cfg_named_msg_event(void *userdata, | 384 | static void cfg_conn_msg_event(int conid, struct sockaddr_tipc *addr, |
385 | u32 port_ref, | 385 | void *usr_data, void *buf, size_t len) |
386 | struct sk_buff **buf, | ||
387 | const unchar *msg, | ||
388 | u32 size, | ||
389 | u32 importance, | ||
390 | struct tipc_portid const *orig, | ||
391 | struct tipc_name_seq const *dest) | ||
392 | { | 386 | { |
393 | struct tipc_cfg_msg_hdr *req_hdr; | 387 | struct tipc_cfg_msg_hdr *req_hdr; |
394 | struct tipc_cfg_msg_hdr *rep_hdr; | 388 | struct tipc_cfg_msg_hdr *rep_hdr; |
395 | struct sk_buff *rep_buf; | 389 | struct sk_buff *rep_buf; |
390 | int ret; | ||
396 | 391 | ||
397 | /* Validate configuration message header (ignore invalid message) */ | 392 | /* Validate configuration message header (ignore invalid message) */ |
398 | req_hdr = (struct tipc_cfg_msg_hdr *)msg; | 393 | req_hdr = (struct tipc_cfg_msg_hdr *)buf; |
399 | if ((size < sizeof(*req_hdr)) || | 394 | if ((len < sizeof(*req_hdr)) || |
400 | (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) || | 395 | (len != TCM_ALIGN(ntohl(req_hdr->tcm_len))) || |
401 | (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) { | 396 | (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) { |
402 | pr_warn("Invalid configuration message discarded\n"); | 397 | pr_warn("Invalid configuration message discarded\n"); |
403 | return; | 398 | return; |
404 | } | 399 | } |
405 | 400 | ||
406 | /* Generate reply for request (if can't, return request) */ | 401 | /* Generate reply for request (if can't, return request) */ |
407 | rep_buf = tipc_cfg_do_cmd(orig->node, | 402 | rep_buf = tipc_cfg_do_cmd(addr->addr.id.node, ntohs(req_hdr->tcm_type), |
408 | ntohs(req_hdr->tcm_type), | 403 | buf + sizeof(*req_hdr), |
409 | msg + sizeof(*req_hdr), | 404 | len - sizeof(*req_hdr), |
410 | size - sizeof(*req_hdr), | ||
411 | BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr)); | 405 | BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr)); |
412 | if (rep_buf) { | 406 | if (rep_buf) { |
413 | skb_push(rep_buf, sizeof(*rep_hdr)); | 407 | skb_push(rep_buf, sizeof(*rep_hdr)); |
@@ -415,57 +409,51 @@ static void cfg_named_msg_event(void *userdata, | |||
415 | memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr)); | 409 | memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr)); |
416 | rep_hdr->tcm_len = htonl(rep_buf->len); | 410 | rep_hdr->tcm_len = htonl(rep_buf->len); |
417 | rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST); | 411 | rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST); |
418 | } else { | ||
419 | rep_buf = *buf; | ||
420 | *buf = NULL; | ||
421 | } | ||
422 | 412 | ||
423 | /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */ | 413 | ret = tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data, |
424 | tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len); | 414 | rep_buf->len); |
415 | if (ret < 0) | ||
416 | pr_err("Sending cfg reply message failed, no memory\n"); | ||
417 | |||
418 | kfree_skb(rep_buf); | ||
419 | } | ||
425 | } | 420 | } |
426 | 421 | ||
422 | static struct sockaddr_tipc cfgsrv_addr __read_mostly = { | ||
423 | .family = AF_TIPC, | ||
424 | .addrtype = TIPC_ADDR_NAMESEQ, | ||
425 | .addr.nameseq.type = TIPC_CFG_SRV, | ||
426 | .addr.nameseq.lower = 0, | ||
427 | .addr.nameseq.upper = 0, | ||
428 | .scope = TIPC_ZONE_SCOPE | ||
429 | }; | ||
430 | |||
431 | static struct tipc_server cfgsrv __read_mostly = { | ||
432 | .saddr = &cfgsrv_addr, | ||
433 | .imp = TIPC_CRITICAL_IMPORTANCE, | ||
434 | .type = SOCK_RDM, | ||
435 | .max_rcvbuf_size = 64 * 1024, | ||
436 | .name = "cfg_server", | ||
437 | .tipc_conn_recvmsg = cfg_conn_msg_event, | ||
438 | .tipc_conn_new = NULL, | ||
439 | .tipc_conn_shutdown = NULL | ||
440 | }; | ||
441 | |||
427 | int tipc_cfg_init(void) | 442 | int tipc_cfg_init(void) |
428 | { | 443 | { |
429 | struct tipc_name_seq seq; | 444 | return tipc_server_start(&cfgsrv); |
430 | int res; | ||
431 | |||
432 | res = tipc_createport(NULL, TIPC_CRITICAL_IMPORTANCE, | ||
433 | NULL, NULL, NULL, | ||
434 | NULL, cfg_named_msg_event, NULL, | ||
435 | NULL, &config_port_ref); | ||
436 | if (res) | ||
437 | goto failed; | ||
438 | |||
439 | seq.type = TIPC_CFG_SRV; | ||
440 | seq.lower = seq.upper = tipc_own_addr; | ||
441 | res = tipc_publish(config_port_ref, TIPC_ZONE_SCOPE, &seq); | ||
442 | if (res) | ||
443 | goto failed; | ||
444 | |||
445 | return 0; | ||
446 | |||
447 | failed: | ||
448 | pr_err("Unable to create configuration service\n"); | ||
449 | return res; | ||
450 | } | 445 | } |
451 | 446 | ||
452 | void tipc_cfg_reinit(void) | 447 | void tipc_cfg_reinit(void) |
453 | { | 448 | { |
454 | struct tipc_name_seq seq; | 449 | tipc_server_stop(&cfgsrv); |
455 | int res; | ||
456 | |||
457 | seq.type = TIPC_CFG_SRV; | ||
458 | seq.lower = seq.upper = 0; | ||
459 | tipc_withdraw(config_port_ref, TIPC_ZONE_SCOPE, &seq); | ||
460 | 450 | ||
461 | seq.lower = seq.upper = tipc_own_addr; | 451 | cfgsrv_addr.addr.nameseq.lower = tipc_own_addr; |
462 | res = tipc_publish(config_port_ref, TIPC_ZONE_SCOPE, &seq); | 452 | cfgsrv_addr.addr.nameseq.upper = tipc_own_addr; |
463 | if (res) | 453 | tipc_server_start(&cfgsrv); |
464 | pr_err("Unable to reinitialize configuration service\n"); | ||
465 | } | 454 | } |
466 | 455 | ||
467 | void tipc_cfg_stop(void) | 456 | void tipc_cfg_stop(void) |
468 | { | 457 | { |
469 | tipc_deleteport(config_port_ref); | 458 | tipc_server_stop(&cfgsrv); |
470 | config_port_ref = 0; | ||
471 | } | 459 | } |
diff --git a/net/tipc/core.c b/net/tipc/core.c index 15bbe99b609d..fd4eeeaa972a 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
@@ -137,8 +137,6 @@ static int tipc_core_start(void) | |||
137 | if (!res) | 137 | if (!res) |
138 | res = tipc_nametbl_init(); | 138 | res = tipc_nametbl_init(); |
139 | if (!res) | 139 | if (!res) |
140 | res = tipc_cfg_init(); | ||
141 | if (!res) | ||
142 | res = tipc_netlink_start(); | 140 | res = tipc_netlink_start(); |
143 | if (!res) | 141 | if (!res) |
144 | res = tipc_socket_init(); | 142 | res = tipc_socket_init(); |
@@ -146,6 +144,8 @@ static int tipc_core_start(void) | |||
146 | res = tipc_register_sysctl(); | 144 | res = tipc_register_sysctl(); |
147 | if (!res) | 145 | if (!res) |
148 | res = tipc_subscr_start(); | 146 | res = tipc_subscr_start(); |
147 | if (!res) | ||
148 | res = tipc_cfg_init(); | ||
149 | if (res) | 149 | if (res) |
150 | tipc_core_stop(); | 150 | tipc_core_stop(); |
151 | 151 | ||
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index d0254157a30d..9510fe8acf45 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -403,7 +403,8 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) | |||
403 | return -EAFNOSUPPORT; | 403 | return -EAFNOSUPPORT; |
404 | 404 | ||
405 | if ((addr->addr.nameseq.type < TIPC_RESERVED_TYPES) && | 405 | if ((addr->addr.nameseq.type < TIPC_RESERVED_TYPES) && |
406 | (addr->addr.nameseq.type != TIPC_TOP_SRV)) | 406 | (addr->addr.nameseq.type != TIPC_TOP_SRV) && |
407 | (addr->addr.nameseq.type != TIPC_CFG_SRV)) | ||
407 | return -EACCES; | 408 | return -EACCES; |
408 | 409 | ||
409 | return (addr->scope > 0) ? | 410 | return (addr->scope > 0) ? |