-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
DHCP for bridge mode (IDFGH-3778) #5697
Comments
Thanks for raising this feature request. |
HI @romatetemadze, Not sure I have understood your requirements:
Could you give more description about why the NAT is not suitable for you? |
Hello, thanks for answering. You can think of an Ethernet+wifi switch that has DHCP server built in. |
Well, so it's a very special requirement and I'm afraid it's NOT common enough to put it into IDF.
If only ETH is UP, will the TCPIP stack be up also? If yes, then it may be problematic, consider following scenario:
|
Thanks for the answer. Will give you a live example. I have a small WIFI router at home, which can be put in BRIDGE mode, so WIFI is transparently translated to ethernet on MAC level, and vice versa. On the same time, it has some sort of a virtual interface (with it's OWN MAC address) which is running DHCP service (regardless of presence of clients at either side). This is what I want to achieve with ESP32. So far, I can catch packet in the code below, analyze if it's DHCP, and respond back with DHCP offer/lease instead of forwarding to opposite media. Similar approach for pkt_wifi2eth side. However, it's already in DHCP driver in ESP, just need good understanding how to run such setup, which I am lacking.
|
hi @romatetemadze
At present, IP address is obtained by bridge, but IDF has not achieved this way. |
Hello, The point is that in my setup neither side is running any DHCP, means clients end up with no IP. I would live with that, but Android is unable to join WIFI AP if IP is not provided. I actually wrote a workaround that catches DHCP option 53 and provides IP/Route to either side, so I guess its good enough. However, I believe such scenario may exist in many different cases, when we want to consolidate ETH and WIFI clients by providing them with IP's from esp32.
And then, on wifi receive, I am checking if its DHCP and responding back if yes. Otherwise, bridging to ETH:
Need to do same for ETH inbound. |
hi @romatetemadze |
Thanks for the response. As I correct solution, I believe this should be done:
There are many routers that allow doing such setup, which is not for general internet access, but mostly for local interconnection between wired and wireless embed clients. I don't see why it may not be a desirable mode of operations? |
hi @romatetemadze |
I believe quite of P2P application would be seeking for such solution. Regardless, I'd anyways provide a virtual interface feature, as its will be commonly used in quite of networking setups with interconnecting two different subnets without NAT'ing the traffic, but routing it. Also, having DHCP standalone would allow interface to be brought down/up without having to restart the DHCP service, which could find some use too. Would you suggest me to open a new feature request while closing this one? Re-reading the subject of this issue, I believe it does say what some applications are looking for - DHCP for interconnecting wired and wireless clients, I'd say it's somewhat TCPIP network for mix of wired and wireless clients with common services (HTTP Server, DHCP, DNS, etc) Sounds like a valuable feature, there are no SOC's which can provide it, and many standalone industrial provisioning servers could be built on ESP32 (there's still STA interface for centralized control or uplink provision if needed). Big mesh'es are usually providing "local" DHCP helpers to avoid huge broadcast traffic over wireless uplinks. |
hi @romatetemadze |
Hello folks, So, any suggestion how to bring a virtual interface with DHCP server into the same bridge as eth/wifi? That definitely has quite of applications. |
hi @romatetemadze
I think this is a big feature. We will discuss whether to add this function internally. |
Hello @freakyxue , Did any discussion happen on this matter so far? I am unable to fully solve this by intercepting DHCP traffic, as them comes ARP and some other services to make a "fake" interface. Furthermore, I would like to run a socket server on some of interfaces to server an application needs. Another question for same problem:
That would solve my problem in fact. |
hi @romatetemadze
Do you think this plan is suitable for you? |
I think that being able to setup bridge between wifi and ethernet in such way that DHCP packets get passed is important in some cases. |
hi @Harvie Now the dual network port function of DHCP has been developed. For example, as mentioned above, different network segments between Ethernet and WiFi can communicate normally. This feature will be released in version 4.4. |
Not sure why would i need that. I already have DHCP server in my network. So if there is properly implemented bridge on esp32 it will pass DHCP packets through it without need for any DHCP specific code running on ESP32. But it makes sense to run DHCP client on the bridge interface, so ESP32 can acquire dynamic adress from the network. |
hi @Harvie This example realizes the transmission from eth to AP. You can see if it can meet your needs? |
This is awesome. Gotta test it 👍 |
Could you please point me to a source where I can learn about it? Thanks. |
It sounds like exactly what I need. Can yoi kindly provide an example? |
If I am following this thread correctly, would this solution also open up the possibility of allowing an ESP32 to OTA over wifi using another ESP32 running the new "bridge" mode as the internet access point? I have a battery operated wireless mesh esp32 that I am trying to update remotely, but no wifi routers are allowed in the environment. There is another ESP32 processor running the cloud access through hardwired ethernet. |
hi @gmdriscoll Idf has existing solutions to your needs. location: esp-idf/examples/ethernet/eth2ap/main/ethernet_example_main.c The specific scheme is as follows: |
@xueyunfei998 - Thank you. Not sure how I missed that. |
It's the same scenario from the OP. A wired ethernet interface connected via the OBD2 plug into a car. The ESP32 acts as OBD2-adapter, handing out DHCP addresses to both the vehicle (via wired ethernet) and a mobile client connected via WiFi. To both the mobile client and the vehicle, it should look like as if they were connected via a Switch with a DHCP server running "somewhere". |
But then you only need to run DHCP server on that ESP32 bridge interface, not the DHCP client (that will run on car and phone) |
Yes. That sounds like the best way, if the bridge ethernet would work w/ WiFi yet. Until then I'm afraid the manual forwarder is the only working solution. |
You can find the very first "work in progress" version of bridge working with option to bridge WiFi AP at https://github.com/kostaond/esp-idf/tre ... ork/bridge |
@kostaond Excellent. I will test and report. Thanks a lot. |
@mickeyl did you have time to test it? If so, do you have any feedback? Thanks. |
@kostaond Sorry for the late response. I have just tested it on an ESP32C6 and it works perfectly:
I wonder about the multiple outputs for DHCP assigning to 192.168.4.2, since I didn't force reconnecting. But it doesn't seem to interfere with the traffic. I have tested "normal" mixed TCP traffic and This is just great. I'd love to use this for my current project -- what's the best way to get myself a 5.1 release with these changes included? Thanks a lot! |
@mickeyl great to here it works as expected! It will take some time the update gets to official release. Currently the update is in internal review and then you will have to wait for official release. Or you could patch it from master to your branch once the update is reviewed and merged. |
Extended LwIP bridge example to support WiFi AP interface and DHCP Server #5697
@kostaond Is it feasible to perhaps rebase your changes to 5.1.1 release? I'd be happy with an unofficial / unsupported release of the LWIP bridging code. |
@mickeyl I think, it should work, cherry pick this commit. |
FWIW, I'm happy to report that this is in 5.2-beta1 and works fine. Thanks again for your work, @kostaond and the whole Espressif team. |
Thank you! It's great to hear it serves you well. |
Hi, does it source code work with W5500 ? Thanks a lot. I want to create an ethernet AP to expand my own wifi to remote place where I can reach by cable. |
Yes, it works very well. My setup is using a W5500 here as well. |
Yes, of course . You can configure it in |
@kostaond The WiFi->ETH bridge still works great and I'm getting good bandwidth, especially considering that the W5500 is an SPI-bottleneck. I have a related question though.... can I provide a TCP service on the bridge interface by the ESP32S3 in parallel to the bridge functionality? Ideally I would have the bridge working, but still being able to offer a web service via WiFi. |
@mickeyl yes, that's possible. You can see that |
@kostaond As the bridge example has a very elaborate setup, I wonder about the proper shutdown sequence. Could you perhaps give some information about how to completely shutdown the ethernet, wifi, bridge + glue? |
@mickeyl frankly speaking, I've actually never tried it yet. It's not that usual on embedded systems. However, we observe similar requests more frequent recently. Therefore we gradually updating the examples to provide deinit sequences too. It's not high priority task though... Feel free to try it by yourself in the meantime ;) The Example of Ethernet deint sequence: esp_eth_driver_uninstall(eth_handle);
phy->del(phy);
mac->del(mac); |
Unable to make two clients connect via esp32 (ETH + WIFI AP)
Based on eth2ap example
Development Kit: [ESP32-Ethernet-Kit V1.1]
Module or chip used: [ESP32-WROVER-B]
IDF version: v4.1-rc
Build System: [CMake]
Compiler version: xtensa-esp32-elf-gcc (crosstool-NG crosstool-ng-1.22.0-80-g6c4433a5) 5.2.0
Operating System: [Windows]
Using an IDE?: [Eclipse]
Power Supply: [USB]
Spent like two weeks trying to solve this, but apparently its not something I can do. My case is as follows:
DHCP interceptor in pkt_wifi2eth & pkt_eth2wifi
Guess its doable to pass the packet back if its a DHCP. Not sure if the MAC setting of the WIFI interface affects such approach.
I have tried to set WIFI AP as default with DHCP
Played a lot with custom subnets, tried NAT but well, its not right way, hence asking here. I believe that following changes can be made:
This may be a nice solution for automotive industry, when car is ENET equipped, and most of modern software providers are working with Android/iOS for diagnostics and programming. In such case existence of single DHCP instance is vital on both interfaces
The text was updated successfully, but these errors were encountered: