net: l2: ppp: possibility to have a custom MRU/MTU

Reading a set MTU from the used net_if when starting LCP.
This enables also other custom MTU/MRU to be set for the link than
the default CONFIG_NET_PPP_MTU_MRU (set by a ppp driver during
initialization).

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
This commit is contained in:
Jani Hirsimäki 2021-10-12 14:14:58 +03:00 committed by Anas Nashif
parent 861f2a741f
commit 8a51a79d89
2 changed files with 12 additions and 4 deletions

View File

@ -9,6 +9,7 @@ LOG_MODULE_DECLARE(net_l2_ppp, CONFIG_NET_L2_PPP_LOG_LEVEL);
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/net_if.h>
#include <net/ppp.h>
#include <random/rand32.h>
@ -380,6 +381,7 @@ int ppp_send_pkt(struct ppp_fsm *fsm, struct net_if *iface,
struct ppp_packet ppp;
struct net_pkt *pkt = NULL;
int ret;
struct ppp_context *ctx = ppp_fsm_ctx(fsm);
if (!iface) {
if (!fsm) {
@ -396,7 +398,7 @@ int ppp_send_pkt(struct ppp_fsm *fsm, struct net_if *iface,
switch (type) {
case PPP_CODE_REJ:
len = net_pkt_get_len(req_pkt);
len = MIN(len, PPP_MRU);
len = MIN(len, ctx->lcp.my_options.mru);
break;
case PPP_CONFIGURE_ACK:
@ -495,7 +497,7 @@ int ppp_send_pkt(struct ppp_fsm *fsm, struct net_if *iface,
goto out_of_mem;
}
data_len = MIN(data_len, PPP_MRU);
data_len = MIN(data_len, ctx->lcp.my_options.mru);
if (data_len > 0) {
if (data_len == sizeof(uint32_t)) {
ret = net_pkt_write_be32(pkt,
@ -1020,6 +1022,7 @@ enum net_verdict ppp_fsm_input(struct ppp_fsm *fsm, uint16_t proto,
uint8_t code, id;
uint16_t length;
int ret;
struct ppp_context *ctx = ppp_fsm_ctx(fsm);
ret = net_pkt_read_u8(pkt, &code);
if (ret < 0) {
@ -1042,7 +1045,7 @@ enum net_verdict ppp_fsm_input(struct ppp_fsm *fsm, uint16_t proto,
return NET_DROP;
}
if (length > PPP_MRU) {
if (length > ctx->lcp.my_options.mru) {
NET_DBG("[%s/%p] Too long msg %d", fsm->name, fsm, length);
return NET_DROP;
}

View File

@ -147,6 +147,11 @@ static void lcp_lower_down(struct ppp_context *ctx)
static void lcp_lower_up(struct ppp_context *ctx)
{
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
/* Get currently set MTU */
ctx->lcp.my_options.mru = net_if_get_mtu(ctx->iface);
#endif
ppp_fsm_lower_up(&ctx->lcp.fsm);
}
@ -304,7 +309,7 @@ static void lcp_init(struct ppp_context *ctx)
ppp_fsm_name_set(&ctx->lcp.fsm, ppp_proto2str(PPP_LCP));
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
ctx->lcp.my_options.mru = PPP_MRU;
ctx->lcp.my_options.mru = net_if_get_mtu(ctx->iface);
ctx->lcp.fsm.my_options.info = lcp_my_options;
ctx->lcp.fsm.my_options.data = ctx->lcp.my_options_data;
ctx->lcp.fsm.my_options.count = ARRAY_SIZE(lcp_my_options);