Skip to content

Commit

Permalink
ppp: Add vty support to maximum-receive-unit
Browse files Browse the repository at this point in the history
  • Loading branch information
acassen committed Feb 7, 2024
1 parent 9024fc0 commit cf374c0
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 30 deletions.
16 changes: 11 additions & 5 deletions src/gtp_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,13 @@ sppp_phase_network(sppp_t *sp)
void
sppp_lcp_init(sppp_t *sp)
{
sp->lcp.opts = (1 << LCP_OPT_MAGIC);
gtp_pppoe_t *pppoe = sp->s_pppoe->pppoe;

__set_bit(LCP_OPT_MAGIC, &sp->lcp.opts);
if (pppoe->mru) {
__set_bit(LCP_OPT_MRU, &sp->lcp.opts);
sp->lcp.mru = pppoe->mru;
}
sp->lcp.magic = 0;
sp->state[IDX_LCP] = STATE_INITIAL;
sp->fail_counter[IDX_LCP] = 0;
Expand Down Expand Up @@ -1064,7 +1070,7 @@ sppp_lcp_up(sppp_t *sp)
timeval_t tv;

sp->pp_alivecnt = 0;
sp->lcp.opts = (1 << LCP_OPT_MAGIC);
__set_bit(LCP_OPT_MAGIC, &sp->lcp.opts);
sp->lcp.magic = 0;
sp->lcp.protos = 0;
sp->lcp.mru = (pppoe->mru && pppoe->mru != PP_MTU) ? pppoe->mru : PP_MTU;
Expand Down Expand Up @@ -1567,7 +1573,7 @@ sppp_lcp_scr(sppp_t *sp)
int i = 0;
uint16_t authproto;

if (sp->lcp.opts & (1 << LCP_OPT_MAGIC)) {
if (__test_bit(LCP_OPT_MAGIC, &sp->lcp.opts)) {
if (!sp->lcp.magic)
sp->lcp.magic = poor_prng(&pppoe->seed);
opt[i++] = LCP_OPT_MAGIC;
Expand All @@ -1578,14 +1584,14 @@ sppp_lcp_scr(sppp_t *sp)
opt[i++] = sp->lcp.magic;
}

if (sp->lcp.opts & (1 << LCP_OPT_MRU)) {
if (__test_bit(LCP_OPT_MRU, &sp->lcp.opts)) {
opt[i++] = LCP_OPT_MRU;
opt[i++] = 4;
opt[i++] = sp->lcp.mru >> 8;
opt[i++] = sp->lcp.mru;
}

if (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) {
if (__test_bit(LCP_OPT_AUTH_PROTO, &sp->lcp.opts)) {
authproto = sp->hisauth.proto;
opt[i++] = LCP_OPT_AUTH_PROTO;
opt[i++] = authproto == PPP_CHAP ? 5: 4;
Expand Down
30 changes: 30 additions & 0 deletions src/gtp_vrf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,31 @@ DEFUN(ip_vrf_pppoe_service_name,
return CMD_SUCCESS;
}

DEFUN(ip_vrf_pppoe_mru,
ip_vrf_pppoe_mru_cmd,
"pppoe maximum-receive-unit INTEGER",
"PPP Over Ethernet\n"
"Maximum Receive Unit\n"
"Integer\n")
{
ip_vrf_t *vrf = vty->index;
gtp_pppoe_t *pppoe = vrf->pppoe;

if (argc < 1) {
vty_out(vty, "%% missing arguments%s", VTY_NEWLINE);
return CMD_WARNING;
}

if (!pppoe) {
vty_out(vty, "%% You MUST configure pppoe interface first%s", VTY_NEWLINE);
return CMD_WARNING;
}

pppoe->mru = strtoul(argv[0], NULL, 10);
return CMD_SUCCESS;
}


/* Configuration writer */
static int
gtp_config_write(vty_t *vty)
Expand Down Expand Up @@ -346,6 +371,10 @@ gtp_config_write(vty_t *vty)
vty_out(vty, " pppoe service-name %s%s"
, pppoe->service_name
, VTY_NEWLINE);
if (pppoe->mru)
vty_out(vty, " pppoe maximum-receive-unit %d%s"
, pppoe->mru
, VTY_NEWLINE);
}
vty_out(vty, "!%s", VTY_NEWLINE);
}
Expand Down Expand Up @@ -373,6 +402,7 @@ gtp_vrf_vty_init(void)
install_element(IP_VRF_NODE, &ip_vrf_pppoe_cmd);
install_element(IP_VRF_NODE, &ip_vrf_pppoe_ac_name_cmd);
install_element(IP_VRF_NODE, &ip_vrf_pppoe_service_name_cmd);
install_element(IP_VRF_NODE, &ip_vrf_pppoe_mru_cmd);

return 0;
}
52 changes: 30 additions & 22 deletions src/include/gtp_ppp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,38 @@
#define ECHO_REPLY 10 /* PPP echo reply */
#define DISC_REQ 11 /* PPP discard request */

#define LCP_OPT_MRU 1 /* maximum receive unit */
#define LCP_OPT_ASYNC_MAP 2 /* async control character map */
#define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */
#define LCP_OPT_QUAL_PROTO 4 /* quality protocol */
#define LCP_OPT_MAGIC 5 /* magic number */
#define LCP_OPT_RESERVED 6 /* reserved */
#define LCP_OPT_PROTO_COMP 7 /* protocol field compression */
#define LCP_OPT_ADDR_COMP 8 /* address/control field compression */

#define IPCP_OPT_ADDRESSES 1 /* both IP addresses; deprecated */
#define IPCP_OPT_COMPRESSION 2 /* IP compression protocol (VJ) */
#define IPCP_OPT_ADDRESS 3 /* local IP address */
#define IPCP_OPT_PRIMDNS 129 /* primary remote dns address */
#define IPCP_OPT_SECDNS 131 /* secondary remote dns address */
enum lcp_opts {
LCP_OPT_MRU = 1, /* maximum receive unit */
LCP_OPT_ASYNC_MAP, /* async control character map */
LCP_OPT_AUTH_PROTO, /* authentication protocol */
LCP_OPT_QUAL_PROTO, /* quality protocol */
LCP_OPT_MAGIC, /* magic number */
LCP_OPT_RESERVED, /* reserved */
LCP_OPT_PROTO_COMP, /* protocol field compression */
LCP_OPT_ADDR_COMP, /* address/control field compression */
};

enum ipcp_opts {
IPCP_OPT_ADDRESSES = 1, /* both IP addresses; deprecated */
IPCP_OPT_COMPRESSION = 2, /* IP compression protocol (VJ) */
IPCP_OPT_ADDRESS = 3, /* local IP address */
IPCP_OPT_PRIMDNS = 129, /* primary remote dns address */
IPCP_OPT_SECDNS = 131, /* secondary remote dns address */
};

/* bitmask value to enable or disable individual IPCP options */
#define SPPP_IPCP_OPT_ADDRESSES 1
#define SPPP_IPCP_OPT_COMPRESSION 2
#define SPPP_IPCP_OPT_ADDRESS 3
#define SPPP_IPCP_OPT_PRIMDNS 4
#define SPPP_IPCP_OPT_SECDNS 5

#define IPV6CP_OPT_IFID 1 /* interface identifier */
#define IPV6CP_OPT_COMPRESSION 2 /* IPv6 compression protocol */
enum ipcp_bitmask {
SPPP_IPCP_OPT_ADDRESSES = 1,
SPPP_IPCP_OPT_COMPRESSION,
SPPP_IPCP_OPT_ADDRESS,
SPPP_IPCP_OPT_PRIMDNS,
SPPP_IPCP_OPT_SECDNS,
};

enum ipv6cp_opts {
IPV6CP_OPT_IFID = 1, /* interface identifier */
IPV6CP_OPT_COMPRESSION, /* IPv6 compression protocol */
};

#define PAP_REQ 1 /* PAP name/password request */
#define PAP_ACK 2 /* PAP acknowledge */
Expand Down
6 changes: 3 additions & 3 deletions src/include/gtp_ppp_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct sdnsreq {
#define IDX_LCP 0 /* idx into state table */

struct slcp {
uint32_t opts; /* LCP options to send (bitfield) */
unsigned long opts; /* LCP options to send (bitfield) */
uint32_t magic; /* local magic number */
uint32_t mru; /* our max receive unit */
uint32_t their_mru; /* their max receive unit */
Expand All @@ -66,7 +66,7 @@ struct slcp {
#define IDX_IPV6CP 2

struct sipcp {
uint32_t opts; /* IPCP options to send (bitfield) */
unsigned long opts; /* IPCP options to send (bitfield) */
uint32_t flags;
#define IPCP_HISADDR_SEEN 1 /* have seen his address already */
#define IPCP_MYADDR_DYN 2 /* my address is dynamically assigned */
Expand Down Expand Up @@ -95,7 +95,7 @@ struct sauth {

typedef struct _sppp {
spppoe_t *s_pppoe; /* PPPoE back-pointer */
uint32_t pp_flags;
unsigned long pp_flags;
uint32_t pp_framebytes; /* number of bytes added by hardware framing */
uint16_t pp_alivecnt; /* keepalive packets counter */
uint16_t pp_loopcnt; /* loopback detection counter */
Expand Down

0 comments on commit cf374c0

Please sign in to comment.