-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add proto to sockets #8752
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
Add proto to sockets #8752
Conversation
espressif port is tested but I couldn't test the raspberry pi because I don't have a device to test it |
looks like raspberrypi_pico and some other builds failed so I will try to fix that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit adds some files that should probably not have been added (os, os.path, etc) with many thousands of lines of content. Please rebase this branch so that these files are not added to our history. If that's beyond your git skills, I can help you figure out how.
The rest looks plausible, based on my small understanding of networking.
//| """Create a new socket | ||
//| | ||
//| :param ~int family: AF_INET or AF_INET6 | ||
//| :param ~int type: SOCK_STREAM, SOCK_DGRAM or SOCK_RAW | ||
//| :param ~int proto: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should probably also add some "proto" named constants to the socketpool object, such as IPPROTO_IP and IPPROTO_ICMP. It might also make sense to state that this value is only used for SOCK_RAW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I can work on this tomorrow.
…r/circuitpython into add-proto-to-sockets Rebase
Could you help me with git rebase @jepler |
Do you have `adafruit/circuitpython as a remote, e.g.:
It might be called
There may well be conflicts that you have to resolve. |
Could I do adafruit/8.2.x because I am adding this on the 8.2.x branch |
I think I did it |
fer sure, and I guess you did |
Yep |
Looks like pre-commit wants a few more changes. Other than that, this looks good to me (but i didn't test) |
What kind of network testing do you want to do with this? Can you write a ping? |
//| """Create a new socket | ||
//| | ||
//| :param ~int family: AF_INET or AF_INET6 | ||
//| :param ~int type: SOCK_STREAM, SOCK_DGRAM or SOCK_RAW | ||
//| :param ~int proto: IPPROTO_TCP or IPPROTO_IP. Only works with SOCK_RAW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I manually passed the value of proto = 1 for ICMP and it works to allow me to create a manual ICMP packet with a raw socket (I've tested it). Unfortunately, it doesn't look like IPPROTO_ICMP = 1 is defined anywhere, in the existing code base.
I've been testing the Raspberry Pi Pico version of this build (some comments were in the associated issue). The results are:
Kudos @carson-coder for enabling this functionality. |
@dhalbert I did successfully do this with the .uf2 from this PR for the RPi Pico and it works well. See my previous comment above for more detailed results. Thanks! |
I think
|
For constantant for the proto parm I just use the Two that already exist |
Should I add every IPPROTO_* constant. And what would I do for the |
You could add only the ones that are actually implemented by Espressif or RP2040 wifi. And yes, add each one, with a docstring underneath. as class constants. |
I just added each one and in the docstring for socket I said that proto can be |
//| IPPROTO_AH: int | ||
//| IPPROTO_DSTOPTS: int | ||
//| IPPROTO_EGP: int | ||
//| IPPROTO_ESP: int | ||
//| IPPROTO_FRAGMENT: int | ||
//| IPPROTO_GRE: int | ||
//| IPPROTO_HOPOPTS: int | ||
//| IPPROTO_ICMP: int | ||
//| IPPROTO_ICMPV6: int | ||
//| IPPROTO_IDP: int | ||
//| IPPROTO_IGMP: int | ||
//| IPPROTO_IPIP: int | ||
//| IPPROTO_IPV6: int | ||
//| IPPROTO_MPTCP: int | ||
//| IPPROTO_NONE: int | ||
//| IPPROTO_PIM: int | ||
//| IPPROTO_PUP: int | ||
//| IPPROTO_RAW: int | ||
//| IPPROTO_ROUTING: int | ||
//| IPPROTO_RSVP: int | ||
//| IPPROTO_SCTP: int | ||
//| IPPROTO_TP: int | ||
//| IPPROTO_UDP: int | ||
//| IPPROTO_UDPLITE: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding them here does not make them available in Python You need to add them around line 221 in this file. But there are too many to add, and most will not be used. Just add a few of the common ones, including ICMP.
For instance, MicroPython defines these common ones:
https://github.com/micropython/micropython/blob/9feb0689eeaca5ce88aedcc680f997a3b4d0221c/extmod/modsocket.c#L640
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPPROTO_ICMP=1 and IPPROTO_RAW=255 are the 2 that'd I'd suggest explicitly adding to those that are already implemented in CP.
CPython's socket doesn't define IPPROTO_IPV4 but the micropython file that was linked did so I am not going to define it because it is not in python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to merge if the CI comes up green. Thanks for taking care of all the details here!
Np |
Nice work! @dhalbert GitHub newbie question here, but it looks like this was merged into a branch (8.2.x). How does it get into main so that it will be available in the CP9.0 codebase? Are there periodic merges from older branches or does it have to be manually done? |
Add #8750