mgw: Add support for setting socket priority from VTY

This is useful for affecting the 802.1Q PCP value without any separate
external packet filter rules for classification.

Change-Id: I69136c6dd114c24b1dace034e75dba5157bac37e
Depends: libosmocore.git I89abffcd125e6d073338a5c6437b9433220e1823
This commit is contained in:
Harald Welte 2021-04-28 19:06:34 +02:00
parent 7802ccc8d6
commit 55a9229922
4 changed files with 30 additions and 6 deletions

View File

@ -143,6 +143,7 @@ struct mgcp_config {
struct mgcp_port_range net_ports;
int endp_dscp;
int endp_priority;
int force_ptime;
@ -208,5 +209,6 @@ int mgcp_send_reset_ep(struct mgcp_endpoint *endp);
int mgcp_send_reset_all(struct mgcp_config *cfg);
int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port, uint8_t dscp);
int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port, uint8_t dscp,
uint8_t prio);
int mgcp_udp_send(int fd, struct osmo_sockaddr *addr, int port, char *buf, int len);

View File

@ -1518,13 +1518,17 @@ static int rx_rtp(struct msgb *msg)
* \param[in] source_addr source (local) address to bind on.
* \param[in] fd associated file descriptor.
* \param[in] port to bind on.
* \param[in] dscp IP DSCP value to use.
* \param[in] prio socket priority to use.
* \returns 0 on success, -1 on ERROR. */
int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port, uint8_t dscp)
int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port, uint8_t dscp,
uint8_t prio)
{
int rc;
rc = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, source_addr, port,
NULL, 0, OSMO_SOCK_F_BIND | OSMO_SOCK_F_DSCP(dscp));
NULL, 0, OSMO_SOCK_F_BIND | OSMO_SOCK_F_DSCP(dscp) |
OSMO_SOCK_F_PRIO(prio));
if (rc < 0) {
LOGP(DRTP, LOGL_ERROR, "failed to bind UDP port (%s:%i).\n",
source_addr, port);
@ -1543,14 +1547,16 @@ static int bind_rtp(struct mgcp_config *cfg, const char *source_addr,
/* NOTE: The port that is used for RTCP is the RTP port incremented by one
* (e.g. RTP-Port = 16000 ==> RTCP-Port = 16001) */
if (mgcp_create_bind(source_addr, &rtp_end->rtp, rtp_end->local_port, cfg->endp_dscp) != 0) {
if (mgcp_create_bind(source_addr, &rtp_end->rtp, rtp_end->local_port,
cfg->endp_dscp, cfg->endp_priority) != 0) {
LOGPENDP(endp, DRTP, LOGL_ERROR,
"failed to create RTP port: %s:%d\n",
source_addr, rtp_end->local_port);
goto cleanup0;
}
if (mgcp_create_bind(source_addr, &rtp_end->rtcp, rtp_end->local_port + 1, cfg->endp_dscp) != 0) {
if (mgcp_create_bind(source_addr, &rtp_end->rtcp, rtp_end->local_port + 1,
cfg->endp_dscp, cfg->endp_priority) != 0) {
LOGPENDP(endp, DRTP, LOGL_ERROR,
"failed to create RTCP port: %s:%d\n",
source_addr, rtp_end->local_port + 1);

View File

@ -418,7 +418,8 @@ int osmux_init(int role, struct mgcp_config *cfg)
osmo_fd_setup(&osmux_fd, -1, OSMO_FD_READ, osmux_read_fd_cb, cfg, 0);
ret = mgcp_create_bind(cfg->osmux_addr, &osmux_fd, cfg->osmux_port, cfg->endp_dscp);
ret = mgcp_create_bind(cfg->osmux_addr, &osmux_fd, cfg->osmux_port,
cfg->endp_dscp, cfg->endp_priority);
if (ret < 0) {
LOGP(DLMGCP, LOGL_ERROR, "cannot bind OSMUX socket to %s:%u\n",
cfg->osmux_addr, cfg->osmux_port);

View File

@ -83,6 +83,8 @@ static int config_write_mgcp(struct vty *vty)
else
vty_out(vty, " no rtp ip-probing%s", VTY_NEWLINE);
vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
if (g_cfg->endp_priority)
vty_out(vty, " rtp socket-priority %d%s", g_cfg->endp_priority, VTY_NEWLINE);
if (trunk->keepalive_interval == MGCP_KEEPALIVE_ONCE)
vty_out(vty, " rtp keep-alive once%s", VTY_NEWLINE);
else if (trunk->keepalive_interval)
@ -588,6 +590,18 @@ DEFUN_USRATTR(cfg_mgcp_rtp_ip_dscp,
return CMD_SUCCESS;
}
DEFUN_USRATTR(cfg_mgcp_rtp_priority,
cfg_mgcp_rtp_priority_cmd,
X(MGW_CMD_ATTR_NEWCONN),
"rtp socket-priority <0-255>",
RTP_STR
"socket priority (values > 6 require CAP_NET_ADMIN)\n" "socket priority value\n")
{
int prio = atoi(argv[0]);
g_cfg->endp_priority = prio;
return CMD_SUCCESS;
}
#define FORCE_PTIME_STR "Force a fixed ptime for packets sent"
DEFUN_USRATTR(cfg_mgcp_rtp_force_ptime,
cfg_mgcp_rtp_force_ptime_cmd,
@ -1618,6 +1632,7 @@ int mgcp_vty_init(void)
install_element(MGCP_NODE, &cfg_mgcp_rtp_net_bind_ip_probing_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_no_net_bind_ip_probing_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_priority_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_force_ptime_cmd);
install_element(MGCP_NODE, &cfg_mgcp_no_rtp_force_ptime_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_keepalive_cmd);