[GPRS] NS: VTY: Move all local ip/port bind values into 'ns' node

This removes the requirement for gb_proxy and sgsn to have duplicate
vty parsing code
This commit is contained in:
Harald Welte 2010-05-19 15:09:09 +02:00
parent 5540c4cbd3
commit ff3bde8b49
11 changed files with 129 additions and 101 deletions

View File

@ -10,11 +10,6 @@
struct gbproxy_config { struct gbproxy_config {
/* parsed from config file */ /* parsed from config file */
u_int32_t nsip_listen_ip;
u_int16_t nsip_listen_port;
int frgre_enabled;
u_int16_t nsip_sgsn_nsei; u_int16_t nsip_sgsn_nsei;
/* misc */ /* misc */

View File

@ -134,10 +134,14 @@ struct gprs_ns_inst {
/* NS-over-IP specific bits */ /* NS-over-IP specific bits */
struct { struct {
struct bsc_fd fd; struct bsc_fd fd;
uint32_t local_ip;
uint16_t local_port;
} nsip; } nsip;
/* NS-over-FR-over-GRE-over-IP specific bits */ /* NS-over-FR-over-GRE-over-IP specific bits */
struct { struct {
struct bsc_fd fd; struct bsc_fd fd;
uint32_t local_ip;
int enabled:1;
} frgre; } frgre;
}; };
@ -188,7 +192,7 @@ struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb);
void gprs_ns_destroy(struct gprs_ns_inst *nsi); void gprs_ns_destroy(struct gprs_ns_inst *nsi);
/* Listen for incoming GPRS packets via NS/UDP */ /* Listen for incoming GPRS packets via NS/UDP */
int nsip_listen(struct gprs_ns_inst *nsi, uint32_t ip, uint16_t udp_port); int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi);
struct sockaddr_in; struct sockaddr_in;
@ -200,7 +204,7 @@ int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause);
int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc); int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc);
/* Listen for incoming GPRS packets via NS/FR/GRE */ /* Listen for incoming GPRS packets via NS/FR/GRE */
int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi, uint32_t ip); int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi);
/* Establish a connection (from the BSS) to the SGSN */ /* Establish a connection (from the BSS) to the SGSN */
struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi, struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi,

View File

@ -10,8 +10,6 @@
struct sgsn_config { struct sgsn_config {
/* parsed from config file */ /* parsed from config file */
u_int32_t nsip_listen_ip;
u_int16_t nsip_listen_port;
char *gtp_statedir; char *gtp_statedir;
struct sockaddr_in gtp_listenaddr; struct sockaddr_in gtp_listenaddr;

View File

@ -238,20 +238,17 @@ int main(int argc, char **argv)
exit(2); exit(2);
} }
rc = nsip_listen(bssgp_nsi, gbcfg.nsip_listen_ip, rc = gprs_ns_nsip_listen(bssgp_nsi);
gbcfg.nsip_listen_port);
if (rc < 0) { if (rc < 0) {
LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n"); LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n");
exit(2); exit(2);
} }
if (gbcfg.frgre_enabled) { rc = gprs_ns_frgre_listen(bssgp_nsi);
rc = gprs_ns_frgre_listen(bssgp_nsi, gbcfg.nsip_listen_ip); if (rc < 0) {
if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE "
LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE " "socket. Do you have CAP_NET_RAW?\n");
"socket. Do you have CAP_NET_RAW?\n"); exit(2);
exit(2);
}
} }
/* Reset all the persistent NS-VCs that we've read from the config */ /* Reset all the persistent NS-VCs that we've read from the config */

View File

@ -51,14 +51,7 @@ static int config_write_gbproxy(struct vty *vty)
vty_out(vty, "gbproxy%s", VTY_NEWLINE); vty_out(vty, "gbproxy%s", VTY_NEWLINE);
if (g_cfg->nsip_listen_ip) { vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
ia.s_addr = htonl(g_cfg->nsip_listen_ip);
vty_out(vty, " nsip bss local ip %s%s", inet_ntoa(ia),
VTY_NEWLINE);
}
vty_out(vty, " nsip bss local port %u%s", g_cfg->nsip_listen_port,
VTY_NEWLINE);
vty_out(vty, " nsip sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
VTY_NEWLINE); VTY_NEWLINE);
return CMD_SUCCESS; return CMD_SUCCESS;
@ -73,33 +66,9 @@ DEFUN(cfg_gbproxy,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFUN(cfg_nsip_bss_local_ip,
cfg_nsip_bss_local_ip_cmd,
"nsip bss local ip A.B.C.D",
"Set the IP address on which we listen for BSS connects")
{
struct in_addr ia;
inet_aton(argv[0], &ia);
g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
return CMD_SUCCESS;
}
DEFUN(cfg_nsip_bss_local_port,
cfg_nsip_bss_local_port_cmd,
"nsip bss local port <0-65534>",
"Set the UDP port on which we listen for BSS connects")
{
unsigned int port = atoi(argv[0]);
g_cfg->nsip_listen_port = port;
return CMD_SUCCESS;
}
DEFUN(cfg_nsip_sgsn_nsei, DEFUN(cfg_nsip_sgsn_nsei,
cfg_nsip_sgsn_nsei_cmd, cfg_nsip_sgsn_nsei_cmd,
"nsip sgsn nsei <0-65534>", "sgsn nsei <0-65534>",
"Set the NSEI to be used in the connection with the SGSN") "Set the NSEI to be used in the connection with the SGSN")
{ {
unsigned int port = atoi(argv[0]); unsigned int port = atoi(argv[0]);
@ -117,8 +86,6 @@ int gbproxy_vty_init(void)
install_default(GBPROXY_NODE); install_default(GBPROXY_NODE);
install_element(GBPROXY_NODE, &ournode_exit_cmd); install_element(GBPROXY_NODE, &ournode_exit_cmd);
install_element(GBPROXY_NODE, &ournode_end_cmd); install_element(GBPROXY_NODE, &ournode_end_cmd);
install_element(GBPROXY_NODE, &cfg_nsip_bss_local_ip_cmd);
install_element(GBPROXY_NODE, &cfg_nsip_bss_local_port_cmd);
install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd); install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
return 0; return 0;

View File

@ -903,11 +903,12 @@ static int nsip_fd_cb(struct bsc_fd *bfd, unsigned int what)
} }
/* Listen for incoming GPRS packets */ /* Listen for incoming GPRS packets */
int nsip_listen(struct gprs_ns_inst *nsi, uint32_t ip, uint16_t udp_port) int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi)
{ {
int ret; int ret;
ret = make_sock(&nsi->nsip.fd, IPPROTO_UDP, ip, udp_port, nsip_fd_cb); ret = make_sock(&nsi->nsip.fd, IPPROTO_UDP, nsi->nsip.local_ip,
nsi->nsip.local_port, nsip_fd_cb);
if (ret < 0) if (ret < 0)
return ret; return ret;

View File

@ -202,7 +202,7 @@ static int nsfrgre_fd_cb(struct bsc_fd *bfd, unsigned int what)
return rc; return rc;
} }
int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi, uint32_t ip) int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi)
{ {
int rc; int rc;
@ -210,7 +210,11 @@ int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi, uint32_t ip)
if (nsi->frgre.fd.fd) if (nsi->frgre.fd.fd)
close(nsi->frgre.fd.fd); close(nsi->frgre.fd.fd);
rc = make_sock(&nsi->frgre.fd, IPPROTO_GRE, ip, 0, nsfrgre_fd_cb); if (!nsi->frgre.enabled)
return 0;
rc = make_sock(&nsi->frgre.fd, IPPROTO_GRE, nsi->frgre.local_ip,
0, nsfrgre_fd_cb);
if (rc < 0) { if (rc < 0) {
LOGP(DNS, LOGL_ERROR, "Error creating GRE socket (%s)\n", LOGP(DNS, LOGL_ERROR, "Error creating GRE socket (%s)\n",
strerror(errno)); strerror(errno));

View File

@ -68,6 +68,7 @@ static int config_write_ns(struct vty *vty)
{ {
struct gprs_nsvc *nsvc; struct gprs_nsvc *nsvc;
unsigned int i; unsigned int i;
struct in_addr ia;
vty_out(vty, "ns%s", VTY_NEWLINE); vty_out(vty, "ns%s", VTY_NEWLINE);
@ -111,6 +112,21 @@ static int config_write_ns(struct vty *vty)
get_value_string(gprs_ns_timer_strs, i), get_value_string(gprs_ns_timer_strs, i),
vty_nsi->timeout[i], VTY_NEWLINE); vty_nsi->timeout[i], VTY_NEWLINE);
if (vty_nsi->nsip.local_ip) {
ia.s_addr = htonl(vty_nsi->nsip.local_ip);
vty_out(vty, " encapsulation udp local-ip %s%s",
inet_ntoa(ia), VTY_NEWLINE);
vty_out(vty, " encapsulation udp local-port %u%s",
vty_nsi->nsip.local_port);
}
vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
if (vty_nsi->frgre.enabled) {
ia.s_addr = htonl(vty_nsi->frgre.local_ip);
vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
inet_ntoa(ia), VTY_NEWLINE);
}
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -142,6 +158,15 @@ static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats) static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
{ {
struct gprs_nsvc *nsvc; struct gprs_nsvc *nsvc;
struct in_addr ia;
ia.s_addr = htonl(vty_nsi->nsip.local_ip);
vty_out(vty, "NS-UDP-IP Encapsulation: Local IP: %s, UDP Port: %u%s",
inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
ia.s_addr = htonl(vty_nsi->frgre.local_ip);
vty_out(vty, "NS-FR-GRE-IP Encapsulation: Local IP: %s%s",
inet_ntoa(ia), VTY_NEWLINE);
llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
if (nsvc == nsi->unknown_nsvc) if (nsvc == nsi->unknown_nsvc)
@ -387,6 +412,66 @@ DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
#define ENCAPS_STR "NS encapsulation options\n"
DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
"encapsulation udp local-ip A.B.C.D",
ENCAPS_STR "NS over UDP Encapsulation\n"
"Set the IP address on which we listen for NS/UDP\n"
"IP Address\n")
{
struct in_addr ia;
inet_aton(argv[0], &ia);
vty_nsi->nsip.local_ip = ntohl(ia.s_addr);
return CMD_SUCCESS;
}
DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
"encapsulation udp local-port <0-65535>",
ENCAPS_STR "NS over UDP Encapsulation\n"
"Set the UDP port on which we listen for NS/UDP\n"
"UDP port number\n")
{
unsigned int port = atoi(argv[0]);
vty_nsi->nsip.local_port = port;
return CMD_SUCCESS;
}
DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
"encapsulation framerelay-gre local-ip A.B.C.D",
ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
"Set the IP address on which we listen for NS/FR/GRE\n"
"IP Address\n")
{
struct in_addr ia;
if (!vty_nsi->frgre.enabled) {
vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
return CMD_WARNING;
}
inet_aton(argv[0], &ia);
vty_nsi->frgre.local_ip = ntohl(ia.s_addr);
return CMD_SUCCESS;
}
DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
"encapsulation framerelay-gre enabled (1|0)",
ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
"Enable or disable Frame Relay over GRE\n"
"Enable\n" "Disable\n")
{
int enabled = atoi(argv[0]);
vty_nsi->frgre.enabled = enabled;
return CMD_SUCCESS;
}
DEFUN(nsvc_nsei, nsvc_nsei_cmd, DEFUN(nsvc_nsei, nsvc_nsei_cmd,
"nsvc nsei <0-65535> (block|unblock|reset)", "nsvc nsei <0-65535> (block|unblock|reset)",
"Perform an operation on a NSVC\n" "Perform an operation on a NSVC\n"
@ -472,6 +557,10 @@ int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
install_element(NS_NODE, &cfg_nse_remoterole_cmd); install_element(NS_NODE, &cfg_nse_remoterole_cmd);
install_element(NS_NODE, &cfg_no_nse_cmd); install_element(NS_NODE, &cfg_no_nse_cmd);
install_element(NS_NODE, &cfg_ns_timer_cmd); install_element(NS_NODE, &cfg_ns_timer_cmd);
install_element(NS_NODE, &cfg_nsip_local_ip_cmd);
install_element(NS_NODE, &cfg_nsip_local_port_cmd);
install_element(NS_NODE, &cfg_frgre_enable_cmd);
install_element(NS_NODE, &cfg_frgre_local_ip_cmd);
install_element(ENABLE_NODE, &nsvc_nsei_cmd); install_element(ENABLE_NODE, &nsvc_nsei_cmd);

View File

@ -6,11 +6,19 @@ line vty
no login no login
! !
gbproxy gbproxy
nsip bss local port 23000 sgsn nsei 101
nsip sgsn nsei 101
ns ns
nse 101 nsvci 101 nse 101 nsvci 101
nse 101 remote-ip 192.168.100.239
nse 101 remote-port 7777
nse 101 remote-role sgsn nse 101 remote-role sgsn
nse 101 encapsulation udp nse 101 encapsulation udp
nse 101 remote-ip 192.168.100.239
nse 101 remote-port 7777
timer tns-block 3
timer tns-block-retries 3
timer tns-reset 3
timer tns-reset-retries 3
timer tns-test 30
timer tns-alive 3
timer tns-alive-retries 10
encapsulation framerelay-gre enabled 1
encapsulation framerelay-gre local-ip 0.0.0.0

View File

@ -175,8 +175,9 @@ int main(int argc, char **argv)
if (rc) if (rc)
exit(2); exit(2);
nsip_listen(sgsn_nsi, sgsn_inst.cfg.nsip_listen_ip, rc = gprs_ns_nsip_listen(sgsn_nsi);
sgsn_inst.cfg.nsip_listen_port); if (rc)
exit(2);
while (1) { while (1) {
rc = bsc_select_main(0); rc = bsc_select_main(0);

View File

@ -54,18 +54,10 @@ static int config_write_sgsn(struct vty *vty)
vty_out(vty, "sgsn%s", VTY_NEWLINE); vty_out(vty, "sgsn%s", VTY_NEWLINE);
if (g_cfg->nsip_listen_ip) {
ia.s_addr = htonl(g_cfg->nsip_listen_ip);
vty_out(vty, " nsip local ip %s%s", inet_ntoa(ia),
VTY_NEWLINE);
}
vty_out(vty, " nsip local port %u%s", g_cfg->nsip_listen_port,
VTY_NEWLINE);
llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) { llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) {
vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id, vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id,
inet_ntoa(gctx->remote_addr), VTY_NEWLINE); inet_ntoa(gctx->remote_addr), VTY_NEWLINE);
vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id, vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id,
gctx->gtp_version, VTY_NEWLINE); gctx->gtp_version, VTY_NEWLINE);
} }
@ -81,32 +73,6 @@ DEFUN(cfg_sgsn,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFUN(cfg_nsip_local_ip,
cfg_nsip_local_ip_cmd,
"nsip local ip A.B.C.D",
"Set the IP address on which we listen for BSS connects")
{
struct in_addr ia;
inet_aton(argv[0], &ia);
g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
return CMD_SUCCESS;
}
DEFUN(cfg_nsip_local_port,
cfg_nsip_local_port_cmd,
"nsip local port <0-65534>",
"Set the UDP port on which we listen for BSS connects")
{
unsigned int port = atoi(argv[0]);
g_cfg->nsip_listen_port = port;
return CMD_SUCCESS;
}
DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd, DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd,
"ggsn <0-255> remote-ip A.B.C.D", "ggsn <0-255> remote-ip A.B.C.D",
"") "")
@ -288,8 +254,6 @@ int sgsn_vty_init(void)
install_default(SGSN_NODE); install_default(SGSN_NODE);
install_element(SGSN_NODE, &ournode_exit_cmd); install_element(SGSN_NODE, &ournode_exit_cmd);
install_element(SGSN_NODE, &ournode_end_cmd); install_element(SGSN_NODE, &ournode_end_cmd);
install_element(SGSN_NODE, &cfg_nsip_local_ip_cmd);
install_element(SGSN_NODE, &cfg_nsip_local_port_cmd);
install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd); install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd);
//install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd); //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd);
install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd); install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd);