8000 Add `IP_RECVTTL` and `IP_RECVERR` constants to `socket` module · Issue #120056 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Add IP_RECVTTL and IP_RECVERR constants to socket module #120056

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

Closed
sobolevn opened this issue Jun 4, 2024 · 0 comments
Closed

Add IP_RECVTTL and IP_RECVERR constants to socket module #120056

sobolevn opened this issue Jun 4, 2024 · 0 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@sobolevn
Copy link
Member
sobolevn commented Jun 4, 2024

Feature or enhancement

I recently needed these three constants in a real code, I had to create them manually.

Docs from Linux: https://man7.org/linux/man-pages/man7/ip.7.html

       IP_RECVERR (since Linux 2.2)
              Enable extended reliable error message passing.  When
              enabled on a datagram socket, all generated errors will be
              queued in a per-socket error queue.  When the user
              receives an error from a socket operation, the errors can
              be received by calling [recvmsg(2)](https://man7.org/linux/man-pages/man2/recvmsg.2.html) with the MSG_ERRQUEUE
              flag set.  The sock_extended_err structure describing the
              error will be passed in an ancillary message with the type
              IP_RECVERR and the level IPPROTO_IP.  This is useful for
              reliable error handling on unconnected sockets.  The
              received data portion of the error queue contains the
              error packet.

              The IP_RECVERR control message contains a
              sock_extended_err structure:

                  #define SO_EE_ORIGIN_NONE    0
                  #define SO_EE_ORIGIN_LOCAL   1
                  #define SO_EE_ORIGIN_ICMP    2
                  #define SO_EE_ORIGIN_ICMP6   3

                  struct sock_extended_err {
                      uint32_t ee_errno;   /* error number */
                      uint8_t  ee_origin;  /* where the error originated */
                      uint8_t  ee_type;    /* type */
                      uint8_t  ee_code;    /* code */
                      uint8_t  ee_pad;
                      uint32_t ee_info;    /* additional information */
                      uint32_t ee_data;    /* other data */
                      /* More data may follow */
                  };

                  struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);

              ee_[errno](https://man7.org/linux/man-pages/man3/errno.3.html) contains the errno number of the queued error.
              ee_origin is the origin code of where the error
              originated.  The other fields are protocol-specific.  The
              macro SO_EE_OFFENDER returns a pointer to the address of
              the network object where the error originated from given a
              pointer to the ancillary message.  If this address is not
              known, the sa_family member of the sockaddr contains
              AF_UNSPEC and the other fields of the sockaddr are
              undefined.

              IP uses the sock_extended_err structure as follows:
              ee_origin is set to SO_EE_ORIGIN_ICMP for errors received
              as an ICMP packet, or SO_EE_ORIGIN_LOCAL for locally
              generated errors.  Unknown values should be ignored.
              ee_type and ee_code are set from the type and code fields
              of the ICMP header.  ee_info contains the discovered MTU
              for EMSGSIZE errors.  The message also contains the
              sockaddr_in of the node caused the error, which can be
              accessed with the SO_EE_OFFENDER macro.  The sin_family
              field of the SO_EE_OFFENDER address is AF_UNSPEC when the
              source was unknown.  When the error originated from the
              network, all IP options (IP_OPTIONS, IP_TTL, etc.) enabled
              on the socket and contained in the error packet are passed
              as control messages.  The payload of the packet causing
              the error is returned as normal payload.  Note that TCP
              has no error queue; MSG_ERRQUEUE is not permitted on
              SOCK_STREAM sockets.  IP_RECVERR is valid for TCP, but all
              errors are returned by socket function return or SO_ERROR
              only.

              Fo
8000
r raw sockets, IP_RECVERR enables passing of all
              received ICMP errors to the application, otherwise errors
              are reported only on connected sockets

              It sets or retrieves an integer boolean flag.  IP_RECVERR
              defaults to off.

       IP_RECVTTL (since Linux 2.2)
              When this flag is set, pass a IP_TTL control message with
              the time-to-live field of the received packet as a 32 bit
              integer.  Not supported for SOCK_STREAM sockets.

Linked PRs

@sobolevn sobolevn added type-feature A feature request or enhancement stdlib Python modules in the Lib dir labels Jun 4, 2024
@sobolevn sobolevn self-assigned this Jun 4, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Jun 4, 2024
jeremyhylton pushed a commit that referenced this issue Jun 12, 2024
…ocket` module (#120058)

* gh-120056: Add `IP_RECVERR` and `IP_RECVTTL` to `socket` module

* Fix news

* Address review

* Update NEWS
@hugovk hugovk closed this as completed Jun 15, 2024
mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
… to `socket` module (python#120058)

* pythongh-120056: Add `IP_RECVERR` and `IP_RECVTTL` to `socket` module

* Fix news

* Address review

* Update NEWS
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
… to `socket` module (python#120058)

* pythongh-120056: Add `IP_RECVERR` and `IP_RECVTTL` to `socket` module

* Fix news

* Address review

* Update NEWS
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
… to `socket` module (python#120058)

* pythongh-120056: Add `IP_RECVERR` and `IP_RECVTTL` to `socket` module

* Fix news

* Address review

* Update NEWS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants
0