diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-02-22 13:29:09 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-02-25 12:12:28 +0100 |
commit | 0db1d43c0d6bdf4c2e67a07ebf77923e9e191aff (patch) | |
tree | 43115ff14d48510eb0de206dcfff3562c9e6c037 | |
parent | 86fc3c8787a9c29f566a44969d528a604ee7e11f (diff) |
ipa driver: make bind address vty configurable
Add VTY function to set the ipa bind address:
e1_input
ipa bind A.B.C.D
Add a priv pointer to struct e1inp_driver in order to communicate the bind
address parameter to ipaccess_line_update(). Add two "internal.h" functions to
get/set it in the ipa driver struct.
Add static ip_bind_addr() to use the IP address set from the VTY or, if NULL,
use "0.0.0.0". Apply in ipaccess_line_update().
-rw-r--r-- | include/internal.h | 3 | ||||
-rw-r--r-- | include/osmocom/abis/e1_input.h | 1 | ||||
-rw-r--r-- | src/e1_input_vty.c | 19 | ||||
-rw-r--r-- | src/input/ipaccess.c | 23 |
4 files changed, 44 insertions, 2 deletions
diff --git a/include/internal.h b/include/internal.h index 7f6e31a..c931d4f 100644 --- a/include/internal.h +++ b/include/internal.h @@ -13,6 +13,9 @@ extern void *libosmo_abis_ctx; /* use libosmo_abis_init, this is only for internal use. */ void e1inp_init(void); +void e1inp_ipa_set_bind_addr(const char *ip_bind_addr); +const char *e1inp_ipa_get_bind_addr(void); + /* ipaccess.c requires these functions defined here */ struct msgb; struct msgb *ipa_msg_alloc(int headroom); diff --git a/include/osmocom/abis/e1_input.h b/include/osmocom/abis/e1_input.h index e5d2991..4f73749 100644 --- a/include/osmocom/abis/e1_input.h +++ b/include/osmocom/abis/e1_input.h @@ -139,6 +139,7 @@ struct e1inp_driver { void (*vty_show)(struct vty *vty, struct e1inp_line *line); int default_delay; int has_keepalive; + const char *bind_addr; }; struct e1inp_line_ops { diff --git a/src/e1_input_vty.c b/src/e1_input_vty.c index 0b4adb2..5320bb3 100644 --- a/src/e1_input_vty.c +++ b/src/e1_input_vty.c @@ -168,6 +168,17 @@ DEFUN(cfg_e1inp, cfg_e1inp_cmd, return CMD_SUCCESS; } +DEFUN(cfg_ipa_bind, + cfg_ipa_bind_cmd, + "ipa bind A.B.C.D", + "ipa driver config\n" + "Set ipa local bind address\n" + "Listen on this IP address (default 0.0.0.0)\n") +{ + e1inp_ipa_set_bind_addr(argv[0]); + return CMD_SUCCESS; +} + static int e1inp_config_write(struct vty *vty) { struct e1inp_line *line; @@ -202,6 +213,12 @@ static int e1inp_config_write(struct vty *vty) VTY_NEWLINE); } + + const char *ipa_bind = e1inp_ipa_get_bind_addr(); + if (ipa_bind && (strcmp(ipa_bind, "0.0.0.0") != 0)) + vty_out(vty, " ipa bind %s%s", + ipa_bind, VTY_NEWLINE); + return CMD_SUCCESS; } @@ -351,6 +368,8 @@ int e1inp_vty_init(void) install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_params_cmd); install_element(L_E1INP_NODE, &cfg_e1_line_no_keepalive_cmd); + install_element(L_E1INP_NODE, &cfg_ipa_bind_cmd); + install_element_ve(&show_e1drv_cmd); install_element_ve(&show_e1line_cmd); install_element_ve(&show_e1ts_cmd); diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 8ffdb19..a4c75b2 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -831,7 +831,8 @@ static int ipaccess_line_update(struct e1inp_line *line) LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n"); oml_link = ipa_server_link_create(tall_ipa_ctx, line, - "0.0.0.0", IPA_TCP_PORT_OML, + e1inp_ipa_get_bind_addr(), + IPA_TCP_PORT_OML, ipaccess_bsc_oml_cb, NULL); if (oml_link == NULL) { LOGP(DLINP, LOGL_ERROR, "cannot create OML " @@ -845,7 +846,8 @@ static int ipaccess_line_update(struct e1inp_line *line) return -EIO; } rsl_link = ipa_server_link_create(tall_ipa_ctx, line, - "0.0.0.0", IPA_TCP_PORT_RSL, + e1inp_ipa_get_bind_addr(), + IPA_TCP_PORT_RSL, ipaccess_bsc_rsl_cb, NULL); if (rsl_link == NULL) { LOGP(DLINP, LOGL_ERROR, "cannot create RSL " @@ -944,3 +946,20 @@ void e1inp_ipaccess_init(void) tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa"); e1inp_driver_register(&ipaccess_driver); } + +void e1inp_ipa_set_bind_addr(const char *ip_bind_addr) +{ + talloc_free((char*)ipaccess_driver.bind_addr); + ipaccess_driver.bind_addr = NULL; + + if (ip_bind_addr) + ipaccess_driver.bind_addr = talloc_strdup(tall_ipa_ctx, + ip_bind_addr); +} + +const char *e1inp_ipa_get_bind_addr(void) +{ + return ipaccess_driver.bind_addr? + ipaccess_driver.bind_addr + : "0.0.0.0"; +} |