Skip to content

Conversation

@glebius
Copy link
Contributor

@glebius glebius commented Dec 19, 2025

@glebius
Copy link
Contributor Author

glebius commented Dec 21, 2025

Tag @vstinner who handled the initial submission of PF_DIVERT.

@vstinner
Copy link
Member

The example from the issue still fails after applying this change:

vstinner@freebsd$ cat raw.py 
from socket import socket, PF_DIVERT, SOCK_RAW
with socket(PF_DIVERT, SOCK_RAW, 0) as fd:
        r = fd.recvfrom(16384)

vstinner@freebsd$ ./python raw.py
Traceback (most recent call last):
  File "/usr/home/vstinner/python/main/raw.py", line 2, in <module>
    with socket(PF_DIVERT, SOCK_RAW, 0) as fd:
         ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/home/vstinner/python/main/Lib/socket.py", line 237, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 47] Address family not supported by protocol family

@glebius
Copy link
Contributor Author

glebius commented Dec 22, 2025

The example from the issue still fails after applying this change:
OSError: [Errno 47] Address family not supported by protocol family

What FreeBSD version do you test on? The GENERIC kernel doesn't have divert module. Do you have ipdivert.ko loaded?

@vstinner
Copy link
Member

vstinner commented Jan 6, 2026

What FreeBSD version do you test on? The GENERIC kernel doesn't have divert module. Do you have ipdivert.ko loaded?

I tested on:

vstinner@freebsd$ uname -a
FreeBSD freebsd 14.2-RELEASE-p1 FreeBSD 14.2-RELEASE-p1 GENERIC amd64

Ah! The example works if I load the kernel module with sudo kldload ipdivert.ko and run the example as root (sudo ./python raw.py).

@vstinner
Copy link
Member

vstinner commented Jan 6, 2026

Without this change, the example fails with:

Traceback (most recent call last):
  File "/usr/home/vstinner/python/main/raw.py", line 3, in <module>
    r = fd.recvfrom(16384)
OSError: getsockaddrlen: bad family

@vstinner vstinner added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 6, 2026
@vstinner vstinner merged commit 05406b2 into python:main Jan 6, 2026
50 checks passed
@miss-islington-app
Copy link

Thanks @glebius for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 6, 2026
…ocket (pythonGH-142993)

(cherry picked from commit 05406b2)

Co-authored-by: Gleb Smirnoff <glebius@FreeBSD.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 6, 2026
…ocket (pythonGH-142993)

(cherry picked from commit 05406b2)

Co-authored-by: Gleb Smirnoff <glebius@FreeBSD.org>
@bedevere-app
Copy link

bedevere-app bot commented Jan 6, 2026

GH-143481 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jan 6, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 6, 2026

GH-143482 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jan 6, 2026
@vstinner
Copy link
Member

vstinner commented Jan 6, 2026

Merged, thanks. I backported the fix to 3.13 and 3.14 branches.

vstinner pushed a commit that referenced this pull request Jan 6, 2026
…socket (GH-142993) (#143482)

gh-142991: socketmodule: fixed getsockaddrlen() for PF_DIVERT socket (GH-142993)
(cherry picked from commit 05406b2)

Co-authored-by: Gleb Smirnoff <glebius@FreeBSD.org>
@glebius
Copy link
Contributor Author

glebius commented Jan 6, 2026

Thanks, Victor!

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD14 3.13 (tier-3) has failed when building commit 7f93669.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1481/builds/1800) and take a look at the build logs.
  4. Check if the failure is related to this commit (7f93669) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1481/builds/1800

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 14, done.        
remote: Counting objects:  12% (1/8)        
remote: Counting objects:  25% (2/8)        
remote: Counting objects:  37% (3/8)        
remote: Counting objects:  50% (4/8)        
remote: Counting objects:  62% (5/8)        
remote: Counting objects:  75% (6/8)        
remote: Counting objects:  87% (7/8)        
remote: Counting objects: 100% (8/8)        
remote: Counting objects: 100% (8/8), done.        
remote: Compressing objects:  12% (1/8)        
remote: Compressing objects:  25% (2/8)        
remote: Compressing objects:  37% (3/8)        
remote: Compressing objects:  50% (4/8)        
remote: Compressing objects:  62% (5/8)        
remote: Compressing objects:  75% (6/8)        
remote: Compressing objects:  87% (7/8)        
remote: Compressing objects: 100% (8/8)        
remote: Compressing objects: 100% (8/8), done.        
remote: Total 14 (delta 1), reused 2 (delta 0), pack-reused 6 (from 2)        
From https://github.com/python/cpython
 * branch                    3.13       -> FETCH_HEAD
Note: switching to '7f936694dbc0dc0dbb07d98fa668776c4e4ca595'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 7f936694dbc [3.13] gh-142991: socketmodule: fixed getsockaddrlen() for PF_DIVERT socket (GH-142993) (#143482)
Switched to and reset branch '3.13'

1 error

@vstinner
Copy link
Member

vstinner commented Jan 7, 2026

Oops, the 3.13 backport broke the build on FreeBSD. I wrote #143514 to fix it.

vstinner pushed a commit that referenced this pull request Jan 7, 2026
…socket (GH-142993) (#143481)

gh-142991: socketmodule: fixed getsockaddrlen() for PF_DIVERT socket (GH-142993)
(cherry picked from commit 05406b2)

Co-authored-by: Gleb Smirnoff <glebius@FreeBSD.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants