Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/shell/lwip: add IPv4 configuration to lwip ifconfig command #19849

Merged

Conversation

krzysztof-cabaj
Copy link
Contributor

Contribution description

This PR adds to lwip ifconfig shell command, ability to configure IPv4 address, mask and gateway.

Testing procedure

Enable in example/gcoap lwip IPv4 stack: in Makefile, line 17 change:

LWIP_IPV4 ?= 0

to

LWIP_IPV4 ?= 1

Configure tap0 interface:

sudo ip tuntap add tap0 mode tap user ${USER}
sudo ip link set tap0 up

Compile example and run it with tap0 interface:

make clean
make
./bin/native/gcoap_example.elf tap0

Test new subcommands added to ifconfig command:

ifconfig help
ifconfig add4 ...

Issues/PRs references

None

@github-actions github-actions bot added the Area: sys Area: System label Jul 27, 2023
@benpicco benpicco requested a review from yarrick July 28, 2023 11:22
@yarrick
Copy link
Contributor

yarrick commented Sep 17, 2023

I think the right way to go is to add ways of setting it as an opt (continuing on #18069) so that the ifconfig command can share most of the code between the IP stacks.

@krzysztof-cabaj
Copy link
Contributor Author

Hi!

So you idea is to add appropriate ifconfig <if_id> set <key> <value> command? Something like ifconfig 6 set addr 192.168.1.2, ifconfig 6 set mask 255.255.255.0, etc. ?

@github-actions github-actions bot added Area: network Area: Networking Area: pkg Area: External package ports labels Oct 11, 2023
@krzysztof-cabaj
Copy link
Contributor Author

I looked through implementation of ifconfig set from gnrc_netif.c and try to implement configuration of LWIP IPv4 in similar manner. The most recent commits contains initial version of the code - setting ip4 address.

@miri64 @yarrick could you be so kind and looked at this code and comment it before I provide full implementation of all options associated with IPv4 configuration?

@yarrick
Copy link
Contributor

yarrick commented Oct 11, 2023

For IPv4 I started in 0b48789 but having separate opts for the different type of addresses like you proposed is better. (edit: or maybe since they have to be set together it makes sense to have them in one group? See netifapi_netif_set_addr in lwIP)

I sent a PR now for removing the last blockers (I think) for using the gnrc_netif shell command instead of the lwIP one.

@krzysztof-cabaj
Copy link
Contributor Author

If I understand your idea well - you plan to use one version of the netif shell module which implements one ifconfig command for all network stacks depending on which is currently used? Good idea.

Please let me know when you end your work and I could move my configuration code.

Accordingly to one NETOPT_IPV4_ADDR I suggest split them into three, my rationale:

  • You could set any (IP, mask, gw) separately - link,
  • I looked at other NET_OPTs and at least most (mayby all) use simple one value to set,
  • There could be a problems in ifconfig set implementation - currently all options take one value, so to set three we have to
    a) add new kind/class of function which takes three values,
    b) add some kind of value separator (for e.g. ; so user have to pass one value - 192.168.1.2;255.255.255.0;192.168,1.1), which looks strange and we have to split this later before we could use,
  • Ability to set only one value for example IP or GW could be beneficial.

Of course on contrary we have to use three ifconfig set commands to fully configure IPv4 stack.

@krzysztof-cabaj
Copy link
Contributor Author

krzysztof-cabaj commented Nov 3, 2023

@yarrick I checkout your branch v4_addr and try to test it using examples/gcoap. When I enable LWIP for IPv4 (set LWIP_IPV4 variable to 1) I assumed that your commands from cmds/gnrc_netif.c will be utilized. However, I still use cmds/lwip_netif.c. How can I enable your code?

Moreover, I would like to know you opinion about spliting IPv4 configuration in three NETOPTs - I provide more details: some pros and cons in the previous post.

@krzysztof-cabaj
Copy link
Contributor Author

Can we move this PR little forward?

Sorry, for bothering - but possibility to change IPv4 address is important for my projects ... and I suspect not only for me.

I have interim solution. Could we add to master legacy style command - ifconfig add4 <interface> <IPv4>/<prefix> gw <IPv4>.
As soon as @yarrick add net opts for IPv4 - I will provide command using set style command and net opts.

@yarrick, @miri64, @benpicco what do you think about such interim solution? If I receive a green light I start cleaning my first version of the code, which provides legacy style command.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not much time at the moment to give this a proper review, maybe @yarrick or @benpicco can help. However, please address the issues pointed out by the static tests regarding the coding conventions and in general keep to them.

sys/shell/cmds/lwip_netif.c Outdated Show resolved Hide resolved
@github-actions github-actions bot removed Area: network Area: Networking Area: pkg Area: External package ports labels Dec 13, 2023
@krzysztof-cabaj krzysztof-cabaj force-pushed the LWIP-ifconfig-IPv4-configuration branch 2 times, most recently from cb2b53a to e177d3f Compare December 13, 2023 16:34
@krzysztof-cabaj
Copy link
Contributor Author

Current version of PR adds legacy style ifconfig command - ifconfig add4 <interface> <IPv4>/<prefix> gw <IPv4>.

@miri64 I think all mistakes associated with coding conversion are fixed. Code is rebased.

@krzysztof-cabaj
Copy link
Contributor Author

@miri64, @yarrick, @benpicco

Could we move this PR little forward? ... and this is not April Fool's Day joke ;)

I think that this feature is not controversial, and making git cherry-pick for each new application is bothersome.

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 1, 2024
@riot-ci
Copy link

riot-ci commented Apr 1, 2024

Murdock results

✔️ PASSED

71d47cd sys/shell/lwip: merge ifconfig add4 and add6 options to one-ifconfig add

Success Failures Total Runtime
10026 0 10027 10m:52s

Artifacts

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for getting back to us and sorry for forgetting about this PR.

The code looks overall fine, intendation is a bit off in some places, but that's an easy fix :)

sys/shell/cmds/lwip_netif.c Outdated Show resolved Hide resolved
sys/shell/cmds/lwip_netif.c Outdated Show resolved Hide resolved
sys/shell/cmds/lwip_netif.c Outdated Show resolved Hide resolved
@krzysztof-cabaj krzysztof-cabaj force-pushed the LWIP-ifconfig-IPv4-configuration branch from 3b71652 to 67abda0 Compare April 2, 2024 08:27
@krzysztof-cabaj krzysztof-cabaj force-pushed the LWIP-ifconfig-IPv4-configuration branch from 493485e to bb98720 Compare April 4, 2024 11:36
@krzysztof-cabaj krzysztof-cabaj force-pushed the LWIP-ifconfig-IPv4-configuration branch from bb98720 to 71d47cd Compare April 4, 2024 11:50
@krzysztof-cabaj
Copy link
Contributor Author

@miri64, @benpicco should I fix or add some functionality to the code to finalize this PR?

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you for the new feature!

@krzysztof-cabaj
Copy link
Contributor Author

Thanks for useful comments and hints. This feature will be beneficial for my students ;)

P.S. Could you add PR to merge queue ... or we wait for more reviews?

@benpicco benpicco added this pull request to the merge queue Apr 10, 2024
Merged via the queue into RIOT-OS:master with commit e3c02f5 Apr 10, 2024
26 checks passed
@MrKevinWeiss MrKevinWeiss added this to the Release 2024.04 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants