lib/vfs/lxip: support configuration of MTU

The MTU can be set via the "mtu" attribute like follows.

  <vfs> <lxip mtu="1200" dhcp="yes"/> </vfs>
This commit is contained in:
Christian Helmuth
2017-11-24 16:50:35 +01:00
parent 96fa3ef28c
commit d5518aa938
6 changed files with 94 additions and 18 deletions

View File

@ -31,7 +31,7 @@ static int driver_net_open(struct net_device *dev)
}
int driver_net_xmit(struct sk_buff *skb, struct net_device *dev)
static int driver_net_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct net_device_stats *stats = (struct net_device_stats*) netdev_priv(dev);
int len = skb->len;
@ -56,10 +56,18 @@ int driver_net_xmit(struct sk_buff *skb, struct net_device *dev)
}
static int driver_change_mtu(struct net_device *dev, int new_mtu)
{
/* possible point to reflect successful MTU setting */
return eth_change_mtu(dev, new_mtu);
}
static const struct net_device_ops driver_net_ops =
{
.ndo_open = driver_net_open,
.ndo_start_xmit = driver_net_xmit,
.ndo_change_mtu = driver_change_mtu,
};

View File

@ -47,6 +47,7 @@ extern "C" void lxip_configure_static(char const *addr,
char const *gateway,
char const *nameserver);
extern "C" void lxip_configure_dhcp();
extern "C" void lxip_configure_mtu(unsigned mtu);
extern "C" bool lxip_do_dhcp();

View File

@ -528,6 +528,22 @@ static void lxip_configure(char const *address_config)
static bool dhcp_configured = false;
static bool dhcp_pending = false;
void lxip_configure_mtu(unsigned mtu)
{
/* zero mtu means reset to default */
unsigned new_mtu = mtu ? mtu : ETH_DATA_LEN;
struct net *net;
struct net_device *dev;
for_each_net(net) {
for_each_netdev(net, dev) {
dev_set_mtu(dev, new_mtu);
}
}
}
void lxip_configure_static(char const *addr, char const *netmask,
char const *gateway, char const *nameserver)
{

View File

@ -1393,15 +1393,19 @@ class Vfs::Lxip_file_system : public Vfs::File_system,
{
typedef String<16> Addr;
try {
unsigned const mtu = config.attribute_value("mtu", 0U);
if (mtu) {
log("Setting MTU to ", mtu);
lxip_configure_mtu(mtu);
} else {
lxip_configure_mtu(0);
}
if (config.attribute_value("dhcp", false)) {
log("Using DHCP for interface configuration.");
lxip_configure_dhcp();
return;
}
} catch (...) { }
if (config.attribute_value("dhcp", false)) {
log("Using DHCP for interface configuration.");
lxip_configure_dhcp();
return;
}
try {
@ -1426,7 +1430,7 @@ class Vfs::Lxip_file_system : public Vfs::File_system,
lxip_configure_static(ip_addr.string(), netmask.string(),
gateway.string(), nameserver.string());
} catch (...) { }
} catch (...) { }
}