NetBSD Problem Report #55446

From www@netbsd.org  Thu Jul  2 11:51:20 2020
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A51BF1A9217
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  2 Jul 2020 11:51:19 +0000 (UTC)
Message-Id: <20200702115118.9BF441A9218@mollari.NetBSD.org>
Date: Thu,  2 Jul 2020 11:51:18 +0000 (UTC)
From: tmp@bh0.amt.ru
Reply-To: tmp@bh0.amt.ru
To: gnats-bugs@NetBSD.org
Subject: scapy function send() does not work
X-Send-Pr-Version: www-1.0

>Number:         55446
>Category:       pkg
>Synopsis:       scapy function send() does not work
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    gutteridge
>State:          suspended
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 02 11:55:00 +0000 2020
>Closed-Date:    
>Last-Modified:  Sun Oct 24 17:50:01 +0000 2021
>Originator:     Alexei
>Release:        NetBSD 8.2, up to date packages
>Organization:
>Environment:
NetBSD 8.2 (GENERIC) #0: Tue Mar 31 05:08:40 UTC 2020  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/i386/compile/GENERIC i386

# pkg_info scapy
Information for scapy-2.4.3nb1:

Comment:
Interactive packet manipulation program

Requires:
py37-setuptools>=0.8
python37>=3.7.0

Description:
Scapy is a powerful interactive packet manipulation program. It is able
to forge or decode packets of a wide number of protocols, send them on
the wire, capture them, match requests and replies, and much more.

Homepage:
http://www.secdev.org/projects/scapy/


# pkg_info py37-setuptools
Information for py37-setuptools-44.0.0:

Comment:
New Python packaging system

Requires:
py37-expat-[0-9]*
python37>=3.7.0

Required by:
scapy-2.4.3nb1
speedtest-cli-2.1.2

Description:
setuptools is a collection of enhancements to the Python distutils
that allow you to more easily build and distribute Python packages,
especially ones that have dependencies on other packages.

Homepage:
https://github.com/pypa/setuptools


# pkg_info python37
Information for python37-3.7.7:

Comment:
Interpreted, interactive, object-oriented programming language

Requires:
libffi>=3.3nb1
libuuid>=2.18
openssl>=1.1.1dnb2

Required by:
py37-setuptools-44.0.0
py37-expat-3.7.7
py37-cElementTree-3.7.7
pango-1.44.7nb2
nghttp2-1.40.0nb2
libxkbcommon-0.10.0
gdk-pixbuf2-2.40.0nb1
atk-2.33.3nb1
scapy-2.4.3nb1
orc-0.4.31
libvdpau-1.3
qt5-qtdeclarative-5.14.1nb2
clang-9.0.1nb1
speedtest-cli-2.1.2
mkfontalias-20000521nb6
url2pkg-19.3.7
json-glib-1.4.4nb1
gexiv2-0.12.0nb3
gobject-introspection-1.64.0
poppler-glib-0.86.1nb1
libsoup-2.70.0
libnotify-0.7.9nb2
yelp-xsl-3.32.1
glib-networking-2.64.0
GConf-3.2.3nb4
at-spi2-atk-2.34.1nb1
at-spi2-core-2.35.1nb1

Description:
Python is an interpreted, interactive, object-oriented
programming language that combines remarkable power with
very clear syntax. For an introduction to programming in
Python you are referred to the Python Tutorial. The
Python Library Reference documents built-in and standard
types, constants, functions and modules. Finally, the
Python Reference Manual describes the syntax and semantics
of the core language in (perhaps too) much detail.

Python's basic power can be extended with your own modules
written in C or C++. On most systems such modules may be
dynamically loaded. Python is also adaptable as an exten-
sion language for existing applications. See the internal
documentation for hints.

This package provides Python version 3.7.x.

Homepage:
https://www.python.org/



>Description:
scapy function send() does not work

>How-To-Repeat:
# cat ./test.py
#! /usr/pkg/bin/python3.7

from scapy.all import *

p=IP(dst="127.0.0.1")/ICMP()/"test"
p.show2()
send(p)


# ./test.py
###[ IP ]###
  version   = 4
  ihl       = 5
  tos       = 0x0
  len       = 32
  id        = 1
  flags     =
  frag      = 0
  ttl       = 64
  proto     = icmp
  chksum    = 0x7cda
  src       = 127.0.0.1
  dst       = 127.0.0.1
  \options   \
###[ ICMP ]###
     type      = echo-request
     code      = 0
     chksum    = 0x1026
     id        = 0x0
     seq       = 0x0
###[ Raw ]###
        load      = 'test'

Traceback (most recent call last):
  File "./test.py", line 7, in <module>
    send(p)
  File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 319, in send
    realtime=realtime, return_packets=return_packets)
  File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 291, in __gen_send
    s.send(p)
  File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 362, in send
    L2bpfSocket.send(self, frame)
  File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
    return os.write(self.outs, raw(x))
OSError: [Errno 47] Address family not supported by protocol family



>Fix:

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: pkg-manager->gutteridge
Responsible-Changed-By: gutteridge@NetBSD.org
Responsible-Changed-When: Fri, 03 Jul 2020 12:08:59 +0000
Responsible-Changed-Why:
Take, since I last updated the package, and am already assigned 54028 for this, too.

From: "David H. Gutteridge" <david@gutteridge.ca>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Fri, 03 Jul 2020 08:49:06 -0400

 > >How-To-Repeat:
 > # cat ./test.py
 > #! /usr/pkg/bin/python3.7
 > 
 > from scapy.all import *
 > 
 > p=IP(dst="127.0.0.1")/ICMP()/"test"
 > p.show2()
 > send(p)
 If you try this instead, what result do you get? (I don't have
 a NetBSD 8.x machine in front of me right now.)

 sendp(Ether()/IP(dst="127.0.0.1")/ICMP(), return_packets=True, realtime=True)

 This is sort of a duplicate of PR pkg/54028, in that some of the
 scapy functionality doesn't work as one would expect. This isn't
 isolated to NetBSD, e.g., I can duplicate issues on DragonFly BSD.
 Really this needs to be reported upstream to the scapy project.

 Dave


From: tmp@bh0.amt.ru
To: gnats-bugs@netbsd.org
Cc: tmp@bh0.amt.ru
Subject: Re: pkg/55446: scapy function send() does not work
Date: Fri, 3 Jul 2020 16:35:09 +0300

 Hello.

 I'd like to clarify the environment of the bug:
 (1) I have no active Ethernet or SLIP interfaces;
 (2) I have active Wi-Fi and tun interfaces.

 According to the "man 4 bpf": "A packet can be sent out on the network
 by writing to a bpf file descriptor.  The writes are unbuffered, meaning
 only one packet can be processed per write.  Currently, only writes to
 Ethernets and SLIP links are supported."

 So I included "conf.use_pcap=True" to the script, ran it, the packet was
 sent, but the tcpdump showed the packet not on the lo0 interface but on
 the Wi-Fi interface iwi0:

 # tcpdump -s 1700 -l# -n -e -tttt -i iwi0 icmp 
 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 listening on iwi0, link-type EN10MB (Ethernet), capture size 1700 bytes
     1  2020-07-03 15:08:35.862011 00:00:00:00:00:00 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 46: 127.0.0.1 > 127.0.0.1: ICMP echo request, id 0, seq 0, length 12

 # ifconfig -a
 bge0: flags=0x8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
         capabilities=3f00<IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx>
         capabilities=3f00<UDP4CSUM_Rx,UDP4CSUM_Tx>
         enabled=0
         ec_capabilities=3<VLAN_MTU,VLAN_HWTAGGING>
         ec_enabled=0
         address: 02:00:00:00:00:21
         media: Ethernet autoselect (none)
         status: no carrier
 iwi0: flags=0x8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
         ssid TEST nwkey:[cut]
         powersave off
         bssid 02:00:00:00:00:01 chan 1
         address: 02:00:00:00:00:11
         media: IEEE802.11 autoselect (OFDM54)
         status: active
         inet 192.0.2.103/24 broadcast 192.0.2.255 flags 0x0
 lo0: flags=0x8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33176
         inet 127.0.0.1/8 flags 0x0
 tun4: flags=0x51<UP,POINTOPOINT,RUNNING> mtu 1143
         inet 198.51.100.29/32 -> 198.51.100.29 flags 0x0

 # netstat -rn -f inet
 Routing tables
 Internet:
 Destination        Gateway            Flags    Refs      Use    Mtu Interface
 default            198.51.100.29      UGS         -        -      -  tun4
 198.51.100/24      198.51.100.29      UGS         -        -      -  tun4
 198.51.100.29      198.51.100.29      UH          -        -      -  tun4
 192.0.2/24         link#2             UC          -        -      -  iwi0
 192.0.2.103        link#2             UHl         -        -      -  lo0
 192.0.2.1          02:00:00:00:00:01  UHL         -        -      -  iwi0
 1.1.1.1            192.0.2.1          UGHS        -        -      -  iwi0
 127/8              127.0.0.1          UGS         -        -  33176  lo0

 Also I tried to use without success remote IP address:

 # cat .BUG.NetBSD-8.2.scapy.send.py 
 #! /usr/pkg/bin/python3.7

 from scapy.all import *

 conf.use_pcap=True
 p=IP(dst="203.0.113.11")/ICMP()/"test"
 p.show()
 send(p)


 # ./.BUG.NetBSD-8.2.scapy.send.py
 ###[ IP ]### 
   version   = 4
   ihl       = None
   tos       = 0x0
   len       = None
   id        = 1
   flags     = 
   frag      = 0
   ttl       = 64
   proto     = icmp
   chksum    = None
   src       = 198.51.100.29
   dst       = 203.0.113.11
   \options   \
 ###[ ICMP ]### 
      type      = echo-request
      code      = 0
      chksum    = None
      id        = 0x0
      seq       = 0x0
 ###[ Raw ]### 
         load      = 'test'

 .
 Sent 1 packets.


 The tcpdump showed the packet not on the tun4 interface but on the Wi-Fi
 interface iwi0 as before:

 # tcpdump -s 1700 -l# -n -e -tttt -i iwi0 icmp 
 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 listening on iwi0, link-type EN10MB (Ethernet), capture size 1700 bytes
     1  2020-07-03 16:11:04.396154 00:00:00:00:00:00 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 46: 198.51.100.29 > 203.0.113.11: ICMP echo request, id 0, seq 0, length 12
 ^C
 1 packet captured
 49 packets received by filter
 0 packets dropped by kernel


 PS. tun4 is an "openconnect" (http://www.infradead.org/openconnect/) VPN
 interface so the traffic via the default route is encrypted on the Wi-Fi
 interface iwi0.


 --
 Alexei


 On 07/02/20 14:55, gnats-admin@netbsd.org wrote:
 > Thank you very much for your problem report.
 > It has the internal identification `pkg/55446'.
 > The individual assigned to look at your
 > report is: pkg-manager. 
 >
 >> Category:       pkg
 >> Responsible:    pkg-manager
 >> Synopsis:       scapy function send() does not work
 >> Arrival-Date:   Thu Jul 02 11:55:00 +0000 2020

From: tmp@bh0.amt.ru
To: gnats-bugs@netbsd.org, gutteridge@netbsd.org, gnats-admin@netbsd.org,
        pkgsrc-bugs@netbsd.org
Cc: tmp@bh0.amt.ru
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Fri, 3 Jul 2020 16:51:10 +0300

 On 07/03/20 15:50, David H. Gutteridge wrote:
 > # cat ./test.py
 >  > #! /usr/pkg/bin/python3.7
 >  > 
 >  > from scapy.all import *
 >  > 
 >  > p=IP(dst="127.0.0.1")/ICMP()/"test"
 >  > p.show2()
 >  > send(p)
 >  If you try this instead, what result do you get? (I don't have
 >  a NetBSD 8.x machine in front of me right now.)
 >  
 >  sendp(Ether()/IP(dst="127.0.0.1")/ICMP(), return_packets=True, realtime=True)

 # scapy
 INFO: Can't import matplotlib. Won't be able to plot.
 INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 INFO: No IPv6 support in kernel
 WARNING: No route found for IPv6 destination :: (no default route?)
 INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)
 INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication.
 WARNING: IPython not available. Using standard Python shell instead.
 AutoCompletion, History are disabled.

                      aSPY//YASa       
              apyyyyCY//////////YCa       |
             sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
  ayp ayyyyyyySCP//Pp           syY//C    | Version git-archive.dev304758016
  AYAsAYYYYYYYY///Ps              cY//S   |
          pCCCCY//p          cSSps y//Y   | https://github.com/secdev/scapy
          SPPPP///a          pP///AC//Y   |
               A//A            cyP////C   | Have fun!
               p///Ac            sC///a   |
               P////YCpc           A//A   | Craft packets before they craft
        scccccp///pSP///p          p//Y   | you.
       sY/////////y  caa           S//P   |                      -- Socrate
        cayCyayP//Ya              pY/Ya   |
         sY/PsY////YCc          aC//Yp 
          sc  sccaCY//PCypaapyCP//YSs  
                   spCPY//////YPSps    
                        ccaacs         

 >>> sendp(Ether()/IP(dst="127.0.0.1")/ICMP(), return_packets=True, realtime=True)
 .
 Sent 1 packets.
 <PacketList: TCP:0 UDP:0 ICMP:1 Other:0>
 >>> sendp(Ether()/IP(dst="127.0.0.1")/ICMP(), return_packets=True, realtime=True)
 .
 Sent 1 packets.
 <PacketList: TCP:0 UDP:0 ICMP:1 Other:0>
 >>> 

 But the tcpdump saw the packets not on the lo0 interface but on the Wi-Fi interface iwi0:

 # tcpdump -s 1700 -l# -n -e -tttt -i lo0 icmp
 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 listening on lo0, link-type NULL (BSD loopback), capture size 1700 bytes
 ^C
 0 packets captured
 49 packets received by filter
 0 packets dropped by kernel

 # tcpdump -s 1700 -l# -n -e -tttt -i iwi0 icmp 
 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 listening on iwi0, link-type EN10MB (Ethernet), capture size 1700 bytes
     1  2020-07-03 16:46:08.442235 00:00:00:00:00:00 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 42: 127.0.0.1 > 127.0.0.1: ICMP echo request, id 0, seq 0, length 8
 ^C
 1 packet captured
 183 packets received by filter
 0 packets dropped by kernel
 # 


 --
 Alexei

From: "David H. Gutteridge" <david@gutteridge.ca>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Sun, 05 Jul 2020 18:24:07 -0400

 I hadn't had occasion to try interacting with a loopback device with
 Scapy before, but I borrowed that example from the Scapy test suite
 (where it recorded a pass for me on NetBSD 8.1 when I ran it while
 doing the last package update), but, the difference is, their test
 example targets the IP address "8.8.8.8". Anyway, you'll want to have a
 look at the following link in the Scapy documentation:

 https://scapy.readthedocs.io/en/latest/troubleshooting.html#i-can-t-ping-127-0-0-1-scapy-does-not-work-with-127-0-0-1-or-on-the-loopback-interface

 Separately...

 >I'd like to clarify the environment of the bug:
 >(1) I have no active Ethernet or SLIP interfaces;
 >(2) I have active Wi-Fi and tun interfaces.
 >
 >According to the "man 4 bpf": "A packet can be sent out on the network
 >by writing to a bpf file descriptor. The writes are unbuffered, meaning
 >only one packet can be processed per write. Currently, only writes to
 >Ethernets and SLIP links are supported."

 I think there may be a documentation issue or two there. That last
 statement is perhaps outdated (I haven't checked in detail), and refers
 to writes to a link layer which Wi-Fi devices also use. (Note your
 tcpdump output states your iwi0 device's "link-type" is "Ethernet".)

 From looking at Scapy commits, it seems NetBSD 8 was the release they
 developed against. So generally we should expect at minimum it's more
 likely to work on 8.x than newer releases.

 I don't use Scapy much; I was using bits of it before for specific
 purposes, but not most of its functionality, so issues with it haven't
 been a priority for me to chase. I think in this case some of this
 issue is better directed to the Scapy project. (I will look into the
 bpf documentation aspect.)

 Dave


From: tmp@bh0.amt.ru
To: gnats-bugs@netbsd.org, gutteridge@netbsd.org, gnats-admin@netbsd.org,
        pkgsrc-bugs@netbsd.org, tmp@bh0.amt.ru
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Fri, 10 Jul 2020 23:34:11 +0300

 On 07/06/20 01:25, David H. Gutteridge wrote:
 > The following reply was made to PR pkg/55446; it has been noted by GNATS.
 >
 > From: "David H. Gutteridge" <david@gutteridge.ca>
 > To: gnats-bugs@netbsd.org
 > Cc: 
 > Subject: Re: pkg/55446 (scapy function send() does not work)
 > Date: Sun, 05 Jul 2020 18:24:07 -0400
 >
 >  I hadn't had occasion to try interacting with a loopback device with
 >  Scapy before, but I borrowed that example from the Scapy test suite
 >  (where it recorded a pass for me on NetBSD 8.1 when I ran it while
 >  doing the last package update), but, the difference is, their test
 >  example targets the IP address "8.8.8.8".

 I tried "8.8.8.8", the result was:

 # scapy 
 INFO: Can't import matplotlib. Won't be able to plot.
 INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 INFO: No IPv6 support in kernel
 WARNING: No route found for IPv6 destination :: (no default route?)
 INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)
 INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication.
 WARNING: IPython not available. Using standard Python shell instead.
 AutoCompletion, History are disabled.

                      aSPY//YASa       
              apyyyyCY//////////YCa       |
             sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
  ayp ayyyyyyySCP//Pp           syY//C    | Version git-archive.dev304758016
  AYAsAYYYYYYYY///Ps              cY//S   |
          pCCCCY//p          cSSps y//Y   | https://github.com/secdev/scapy
          SPPPP///a          pP///AC//Y   |
               A//A            cyP////C   | Have fun!
               p///Ac            sC///a   |
               P////YCpc           A//A   | Craft me if you can.
        scccccp///pSP///p          p//Y   |                   -- IPv6 layer
       sY/////////y  caa           S//P   |
        cayCyayP//Ya              pY/Ya
         sY/PsY////YCc          aC//Yp 
          sc  sccaCY//PCypaapyCP//YSs  
                   spCPY//////YPSps    
                        ccaacs         

 >>> sendp(IP(dst="8.8.8.8")/ICMP()/"test"
 ... help
   File "<console>", line 2
     help
        ^
 SyntaxError: invalid syntax
 >>> 

 I realized that something went wrong.

 > Anyway, you'll want to have a
 >  look at the following link in the Scapy documentation:
 >  
 >  https://scapy.readthedocs.io/en/latest/troubleshooting.html#i-can-t-ping-127-0-0-1-scapy-does-not-work-with-127-0-0-1-or-on-the-loopback-interface

 I tried the above, the result was:

 # scapy
 INFO: Can't import matplotlib. Won't be able to plot.
 INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 INFO: No IPv6 support in kernel
 WARNING: No route found for IPv6 destination :: (no default route?)
 INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)
 INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication.
 WARNING: IPython not available. Using standard Python shell instead.
 AutoCompletion, History are disabled.

                      aSPY//YASa       
              apyyyyCY//////////YCa       |
             sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
  ayp ayyyyyyySCP//Pp           syY//C    | Version git-archive.dev304758016
  AYAsAYYYYYYYY///Ps              cY//S   |
          pCCCCY//p          cSSps y//Y   | https://github.com/secdev/scapy
          SPPPP///a          pP///AC//Y   |
               A//A            cyP////C   | Have fun!
               p///Ac            sC///a   |
               P////YCpc           A//A   | Wanna support scapy? Rate it on
        scccccp///pSP///p          p//Y   | sectools!
       sY/////////y  caa           S//P   | http://sectools.org/tool/scapy/
        cayCyayP//Ya              pY/Ya   |             -- Satoshi Nakamoto
         sY/PsY////YCc          aC//Yp    |
          sc  sccaCY//PCypaapyCP//YSs  
                   spCPY//////YPSps    
                        ccaacs         

 >>> conf.L3socket
 <L3bpfSocket: read/write packets using BPF>
 >>> conf.L3socket=L3RawSocket
 >>> conf.L3socket
 <L3RawSocket: Layer 3 using Raw sockets (PF_INET/SOCK_RAW)>
 >>> p=IP(dst="127.0.0.1")/ICMP()/"test"
 >>> p.show2()
 ###[ IP ]### 
   version= 4
   ihl= 5
   tos= 0x0
   len= 32
   id= 1
   flags= 
   frag= 0
   ttl= 64
   proto= icmp
   chksum= 0x7cda
   src= 127.0.0.1
   dst= 127.0.0.1
   \options\
 ###[ ICMP ]### 
      type= echo-request
      code= 0
      chksum= 0x1026
      id= 0x0
      seq= 0x0
 ###[ Raw ]### 
         load= 'test'

 >>> send(p)
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 316, in send
     socket = socket or conf.L3socket(*args, **kargs)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/supersocket.py", line 150, in __init__
     self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))  # noqa: E501
 AttributeError: module 'socket' has no attribute 'AF_PACKET'

 >  Separately...
 >  
 >  >I'd like to clarify the environment of the bug:
 >  >(1) I have no active Ethernet or SLIP interfaces;
 >  >(2) I have active Wi-Fi and tun interfaces.
 >  >
 >  >According to the "man 4 bpf": "A packet can be sent out on the network
 >  >by writing to a bpf file descriptor. The writes are unbuffered, meaning
 >  >only one packet can be processed per write. Currently, only writes to
 >  >Ethernets and SLIP links are supported."
 >  
 >  I think there may be a documentation issue or two there. That last
 >  statement is perhaps outdated (I haven't checked in detail), and refers
 >  to writes to a link layer which Wi-Fi devices also use. (Note your
 >  tcpdump output states your iwi0 device's "link-type" is "Ethernet".)
 >  
 >  From looking at Scapy commits, it seems NetBSD 8 was the release they
 >  developed against. So generally we should expect at minimum it's more
 >  likely to work on 8.x than newer releases.
 >  
 >  I don't use Scapy much; I was using bits of it before for specific
 >  purposes, but not most of its functionality, so issues with it haven't
 >  been a priority for me to chase. I think in this case some of this
 >  issue is better directed to the Scapy project. (I will look into the
 >  bpf documentation aspect.)
 >  
 >  Dave

 OK. I'll write to the Scapy project.


 --
 Alexei

From: tmp@bh0.amt.ru
To: gnats-bugs@netbsd.org, gutteridge@netbsd.org, gnats-admin@netbsd.org,
        pkgsrc-bugs@netbsd.org, tmp@bh0.amt.ru
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Fri, 10 Jul 2020 23:43:56 +0300

 On 07/10/20 23:35, tmp@bh0.amt.ru wrote:
 > The following reply was made to PR pkg/55446; it has been noted by GNATS.
 >
 > From: tmp@bh0.amt.ru
 > To: gnats-bugs@netbsd.org, gutteridge@netbsd.org, gnats-admin@netbsd.org,
 >         pkgsrc-bugs@netbsd.org, tmp@bh0.amt.ru
 > Cc: 
 > Subject: Re: pkg/55446 (scapy function send() does not work)
 > Date: Fri, 10 Jul 2020 23:34:11 +0300
 >
 >  On 07/06/20 01:25, David H. Gutteridge wrote:
 >  > The following reply was made to PR pkg/55446; it has been noted by GNATS.
 >  >
 >  > From: "David H. Gutteridge" <david@gutteridge.ca>
 >  > To: gnats-bugs@netbsd.org
 >  > Cc: 
 >  > Subject: Re: pkg/55446 (scapy function send() does not work)
 >  > Date: Sun, 05 Jul 2020 18:24:07 -0400
 >  >
 >  >  I hadn't had occasion to try interacting with a loopback device with
 >  >  Scapy before, but I borrowed that example from the Scapy test suite
 >  >  (where it recorded a pass for me on NetBSD 8.1 when I ran it while
 >  >  doing the last package update), but, the difference is, their test
 >  >  example targets the IP address "8.8.8.8".
 >  
 >  I tried "8.8.8.8", the result was:
 >  
 >  # scapy 
 >  INFO: Can't import matplotlib. Won't be able to plot.
 >  INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 >  INFO: No IPv6 support in kernel
 >  WARNING: No route found for IPv6 destination :: (no default route?)
 >  INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)
 >  INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication.
 >  WARNING: IPython not available. Using standard Python shell instead.
 >  AutoCompletion, History are disabled.
 >                                        
 >                       aSPY//YASa       
 >               apyyyyCY//////////YCa       |
 >              sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
 >   ayp ayyyyyyySCP//Pp           syY//C    | Version git-archive.dev304758016
 >   AYAsAYYYYYYYY///Ps              cY//S   |
 >           pCCCCY//p          cSSps y//Y   | https://github.com/secdev/scapy
 >           SPPPP///a          pP///AC//Y   |
 >                A//A            cyP////C   | Have fun!
 >                p///Ac            sC///a   |
 >                P////YCpc           A//A   | Craft me if you can.
 >         scccccp///pSP///p          p//Y   |                   -- IPv6 layer
 >        sY/////////y  caa           S//P   |
 >         cayCyayP//Ya              pY/Ya
 >          sY/PsY////YCc          aC//Yp 
 >           sc  sccaCY//PCypaapyCP//YSs  
 >                    spCPY//////YPSps    
 >                         ccaacs         
 >                                        
 >  >>> sendp(IP(dst="8.8.8.8")/ICMP()/"test"
 >  ... help
 >    File "<console>", line 2
 >      help
 >         ^
 >  SyntaxError: invalid syntax
 >  >>> 

 I'm sorry for the mistake, the right output is:

 >>> send(IP(dst="8.8.8.8")/ICMP()/"test"
 ... help
   File "<console>", line 2
     help
        ^
 SyntaxError: invalid syntax
 >>> 


 >  I realized that something went wrong.
 >  
 >  > Anyway, you'll want to have a
 >  >  look at the following link in the Scapy documentation:
 >  >  
 >  >  https://scapy.readthedocs.io/en/latest/troubleshooting.html#i-can-t-ping-127-0-0-1-scapy-does-not-work-with-127-0-0-1-or-on-the-loopback-interface
 >  
 >  I tried the above, the result was:
 >  
 >  # scapy
 >  INFO: Can't import matplotlib. Won't be able to plot.
 >  INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 >  INFO: No IPv6 support in kernel
 >  WARNING: No route found for IPv6 destination :: (no default route?)
 >  INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)
 >  INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication.
 >  WARNING: IPython not available. Using standard Python shell instead.
 >  AutoCompletion, History are disabled.
 >                                        
 >                       aSPY//YASa       
 >               apyyyyCY//////////YCa       |
 >              sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
 >   ayp ayyyyyyySCP//Pp           syY//C    | Version git-archive.dev304758016
 >   AYAsAYYYYYYYY///Ps              cY//S   |
 >           pCCCCY//p          cSSps y//Y   | https://github.com/secdev/scapy
 >           SPPPP///a          pP///AC//Y   |
 >                A//A            cyP////C   | Have fun!
 >                p///Ac            sC///a   |
 >                P////YCpc           A//A   | Wanna support scapy? Rate it on
 >         scccccp///pSP///p          p//Y   | sectools!
 >        sY/////////y  caa           S//P   | http://sectools.org/tool/scapy/
 >         cayCyayP//Ya              pY/Ya   |             -- Satoshi Nakamoto
 >          sY/PsY////YCc          aC//Yp    |
 >           sc  sccaCY//PCypaapyCP//YSs  
 >                    spCPY//////YPSps    
 >                         ccaacs         
 >                                        
 >  >>> conf.L3socket
 >  <L3bpfSocket: read/write packets using BPF>
 >  >>> conf.L3socket=L3RawSocket
 >  >>> conf.L3socket
 >  <L3RawSocket: Layer 3 using Raw sockets (PF_INET/SOCK_RAW)>
 >  >>> p=IP(dst="127.0.0.1")/ICMP()/"test"
 >  >>> p.show2()
 >  ###[ IP ]### 
 >    version= 4
 >    ihl= 5
 >    tos= 0x0
 >    len= 32
 >    id= 1
 >    flags= 
 >    frag= 0
 >    ttl= 64
 >    proto= icmp
 >    chksum= 0x7cda
 >    src= 127.0.0.1
 >    dst= 127.0.0.1
 >    \options\
 >  ###[ ICMP ]### 
 >       type= echo-request
 >       code= 0
 >       chksum= 0x1026
 >       id= 0x0
 >       seq= 0x0
 >  ###[ Raw ]### 
 >          load= 'test'
 >  
 >  >>> send(p)
 >  Traceback (most recent call last):
 >    File "<console>", line 1, in <module>
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 316, in send
 >      socket = socket or conf.L3socket(*args, **kargs)
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/supersocket.py", line 150, in __init__
 >      self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))  # noqa: E501
 >  AttributeError: module 'socket' has no attribute 'AF_PACKET'
 >  
 >  >  Separately...
 >  >  
 >  >  >I'd like to clarify the environment of the bug:
 >  >  >(1) I have no active Ethernet or SLIP interfaces;
 >  >  >(2) I have active Wi-Fi and tun interfaces.
 >  >  >
 >  >  >According to the "man 4 bpf": "A packet can be sent out on the network
 >  >  >by writing to a bpf file descriptor. The writes are unbuffered, meaning
 >  >  >only one packet can be processed per write. Currently, only writes to
 >  >  >Ethernets and SLIP links are supported."
 >  >  
 >  >  I think there may be a documentation issue or two there. That last
 >  >  statement is perhaps outdated (I haven't checked in detail), and refers
 >  >  to writes to a link layer which Wi-Fi devices also use. (Note your
 >  >  tcpdump output states your iwi0 device's "link-type" is "Ethernet".)
 >  >  
 >  >  From looking at Scapy commits, it seems NetBSD 8 was the release they
 >  >  developed against. So generally we should expect at minimum it's more
 >  >  likely to work on 8.x than newer releases.
 >  >  
 >  >  I don't use Scapy much; I was using bits of it before for specific
 >  >  purposes, but not most of its functionality, so issues with it haven't
 >  >  been a priority for me to chase. I think in this case some of this
 >  >  issue is better directed to the Scapy project. (I will look into the
 >  >  bpf documentation aspect.)
 >  >  
 >  >  Dave
 >  
 >  OK. I'll write to the Scapy project.
 >  
 >  
 >  --
 >  Alexei

From: "David H. Gutteridge" <david@gutteridge.ca>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Tue, 14 Jul 2020 22:22:45 -0400

 On Fri, 2020-07-10 at 23:43 +0300, tmp@bh0.amt.ru wrote:
 > On 07/10/20 23:35, tmp@bh0.amt.ru wrote:
 > >  On 07/06/20 01:25, David H. Gutteridge wrote:
 > >  >  I hadn't had occasion to try interacting with a loopback device with
 > >  >  Scapy before, but I borrowed that example from the Scapy test suite
 > >  >  (where it recorded a pass for me on NetBSD 8.1 when I ran it while
 > >  >  doing the last package update), but, the difference is, their test
 > >  >  example targets the IP address "8.8.8.8".
 > >  
 > >  I tried "8.8.8.8", the result was:
 [...]                                
 > >  >>> sendp(IP(dst="8.8.8.8")/ICMP()/"test"
 > >  ... help
 > >    File "<console>", line 2
 > >      help
 > >         ^
 > >  SyntaxError: invalid syntax
 > >  >>> 
 > 
 > I'm sorry for the mistake, the right output is:
 > 
 > > > > send(IP(dst="8.8.8.8")/ICMP()/"test"
 > ... help
 >   File "<console>", line 2
 >     help
 >        ^
 > SyntaxError: invalid syntax
 > >  I realized that something went wrong.

 I think you're missing a closing bracket in those examples?

 Taking Scapy's ICMP test cases "Sending an ICMP message at layer 2 and
 layer 3" from their test/regression.uts (lines 1337-1344) and running
 them manually (without any prior explicit configration of any kind) on
 8.2_STABLE/amd64, I get something different:

 >>> send(IP(dst="8.8.8.8")/ICMP(), return_packets=True, realtime=True)
 WARNING: Mac address to reach destination not found. Using broadcast.
 .
 Sent 1 packets.
 <PacketList: TCP:0 UDP:0 ICMP:1 Other:0>
 >>> sendp(Ether()/IP(dst="8.8.8.8")/ICMP(), return_packets=True,
 realtime=True)
 WARNING: Mac address to reach destination not found. Using broadcast.
 .
 Sent 1 packets.
 <PacketList: TCP:0 UDP:0 ICMP:1 Other:0>
 >>> 

 (In my case, I have a wired wm0 active.)

 > >  > Anyway, you'll want to have a
 > >  >  look at the following link in the Scapy documentation:
 > >  >  
 > > https://scapy.readthedocs.io/en/latest/troubleshooting.html#i-can-t-ping-127-0-0-1-scapy-does-not-work-with-127-0-0-1-or-on-the-loopback-interface
 > >  
 > >  I tried the above, the result was:
 > >  
 > >  # scapy
 > >  INFO: Can't import matplotlib. Won't be able to plot.
 > >  INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 > >  INFO: No IPv6 support in kernel
 > >  WARNING: No route found for IPv6 destination :: (no default route?)
 > >  INFO: Can't import python-cryptography v1.7+. Disabled WEP
 > > decryption/encryption. (Dot11)
 > >  INFO: Can't import python-cryptography v1.7+. Disabled IPsec
 > > encryption/authentication.
 > >  WARNING: IPython not available. Using standard Python shell
 > > instead.
 > >  AutoCompletion, History are disabled.
 > >                                        
 > >                       aSPY//YASa       
 > >               apyyyyCY//////////YCa       |
 > >              sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
 > >   ayp ayyyyyyySCP//Pp           syY//C    | Version git-
 > > archive.dev304758016
 > >   AYAsAYYYYYYYY///Ps              cY//S   |
 > >           pCCCCY//p          cSSps y//Y   | 
 > > https://github.com/secdev/scapy
 > >           SPPPP///a          pP///AC//Y   |
 > >                A//A            cyP////C   | Have fun!
 > >                p///Ac            sC///a   |
 > >                P////YCpc           A//A   | Wanna support scapy?
 > > Rate it on
 > >         scccccp///pSP///p          p//Y   | sectools!
 > >        sY/////////y  caa           S//P   | 
 > > http://sectools.org/tool/scapy/
 > >         cayCyayP//Ya              pY/Ya   |             -- Satoshi
 > > Nakamoto
 > >          sY/PsY////YCc          aC//Yp    |
 > >           sc  sccaCY//PCypaapyCP//YSs  
 > >                    spCPY//////YPSps    
 > >                         ccaacs         
 > >                                        
 > >  >>> conf.L3socket
 > >  <L3bpfSocket: read/write packets using BPF>
 > >  >>> conf.L3socket=L3RawSocket
 > >  >>> conf.L3socket
 > >  <L3RawSocket: Layer 3 using Raw sockets (PF_INET/SOCK_RAW)>
 > >  >>> p=IP(dst="127.0.0.1")/ICMP()/"test"
 > >  >>> p.show2()
 > >  ###[ IP ]### 
 > >    version= 4
 > >    ihl= 5
 > >    tos= 0x0
 > >    len= 32
 > >    id= 1
 > >    flags= 
 > >    frag= 0
 > >    ttl= 64
 > >    proto= icmp
 > >    chksum= 0x7cda
 > >    src= 127.0.0.1
 > >    dst= 127.0.0.1
 > >    \options\
 > >  ###[ ICMP ]### 
 > >       type= echo-request
 > >       code= 0
 > >       chksum= 0x1026
 > >       id= 0x0
 > >       seq= 0x0
 > >  ###[ Raw ]### 
 > >          load= 'test'
 > >  
 > >  >>> send(p)
 > >  Traceback (most recent call last):
 > >    File "<console>", line 1, in <module>
 > >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py",
 > > line 316, in send
 > >      socket = socket or conf.L3socket(*args, **kargs)
 > >    File "/usr/pkg/lib/python3.7/site-packages/scapy/supersocket.py", 
 > > line 150, in __init__
 > >      self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
 > > socket.htons(type))  # noqa: E501
 > >  AttributeError: module 'socket' has no attribute 'AF_PACKET'
 > >  
 > >  >  Separately...
 > >  >  
 > >  >  >I'd like to clarify the environment of the bug:
 > >  >  >(1) I have no active Ethernet or SLIP interfaces;
 > >  >  >(2) I have active Wi-Fi and tun interfaces.
 > >  >  >
 > >  >  >According to the "man 4 bpf": "A packet can be sent out on the network
 > >  >  >by writing to a bpf file descriptor. The writes are unbuffered, meaning
 > >  >  >only one packet can be processed per write. Currently, only writes to
 > >  >  >Ethernets and SLIP links are supported."
 > >  >  
 > >  >  I think there may be a documentation issue or two there. That last
 > >  >  statement is perhaps outdated (I haven't checked in detail), and refers
 > >  >  to writes to a link layer which Wi-Fi devices also use. (Note your
 > >  >  tcpdump output states your iwi0 device's "link-type" is "Ethernet".)
 > >  >  
 > >  >  From looking at Scapy commits, it seems NetBSD 8 was the release they
 > >  >  developed against. So generally we should expect at minimum it's more
 > >  >  likely to work on 8.x than newer releases.
 > >  >  
 > >  >  I don't use Scapy much; I was using bits of it before for specific
 > >  >  purposes, but not most of its functionality, so issues with it haven't
 > >  >  been a priority for me to chase. I think in this case some of this
 > >  >  issue is better directed to the Scapy project. (I will look into the
 > >  >  bpf documentation aspect.)
 > >  >  
 > >  >  Dave
 > >  
 > >  OK. I'll write to the Scapy project.

 Once submitted, please add the Scapy issue number to this PR. We'll keep
 this open, as it may require something from our end. (Separate from any
 NetBSD documentation that needs to be adjusted still.)

 Dave


From: tmp@bh0.amt.ru
To: gnats-bugs@netbsd.org, gutteridge@netbsd.org, gnats-admin@netbsd.org,
        pkgsrc-bugs@netbsd.org, tmp@bh0.amt.ru
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Fri, 17 Jul 2020 13:07:51 +0300

 On 07/15/20 05:25, David H. Gutteridge wrote:
 > The following reply was made to PR pkg/55446; it has been noted by GNATS.
 >
 > From: "David H. Gutteridge" <david@gutteridge.ca>
 > To: gnats-bugs@netbsd.org
 > Cc: 
 > Subject: Re: pkg/55446 (scapy function send() does not work)
 > Date: Tue, 14 Jul 2020 22:22:45 -0400
 >
 >  On Fri, 2020-07-10 at 23:43 +0300, tmp@bh0.amt.ru wrote:
 >  > On 07/10/20 23:35, tmp@bh0.amt.ru wrote:
 >  > >  On 07/06/20 01:25, David H. Gutteridge wrote:
 >  > >  >  I hadn't had occasion to try interacting with a loopback device with
 >  > >  >  Scapy before, but I borrowed that example from the Scapy test suite
 >  > >  >  (where it recorded a pass for me on NetBSD 8.1 when I ran it while
 >  > >  >  doing the last package update), but, the difference is, their test
 >  > >  >  example targets the IP address "8.8.8.8".
 >  > >  
 >  > >  I tried "8.8.8.8", the result was:
 >  [...]                                
 >  > >  >>> sendp(IP(dst="8.8.8.8")/ICMP()/"test"
 >  > >  ... help
 >  > >    File "<console>", line 2
 >  > >      help
 >  > >         ^
 >  > >  SyntaxError: invalid syntax
 >  > >  >>> 
 >  > 
 >  > I'm sorry for the mistake, the right output is:
 >  > 
 >  > > > > send(IP(dst="8.8.8.8")/ICMP()/"test"
 >  > ... help
 >  >   File "<console>", line 2
 >  >     help
 >  >        ^
 >  > SyntaxError: invalid syntax
 >  > >  I realized that something went wrong.
 >  
 >  I think you're missing a closing bracket in those examples?

 Yes, I'm sorry, the right output is:

 # scapy
 INFO: Can't import matplotlib. Won't be able to plot.
 INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 INFO: No IPv6 support in kernel
 WARNING: No route found for IPv6 destination :: (no default route?)
 INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)
 INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication.
 WARNING: IPython not available. Using standard Python shell instead.
 AutoCompletion, History are disabled.

                      aSPY//YASa       
              apyyyyCY//////////YCa       |
             sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
  ayp ayyyyyyySCP//Pp           syY//C    | Version git-archive.dev304758016
  AYAsAYYYYYYYY///Ps              cY//S   |
          pCCCCY//p          cSSps y//Y   | https://github.com/secdev/scapy
          SPPPP///a          pP///AC//Y   |
               A//A            cyP////C   | Have fun!
               p///Ac            sC///a   |
               P////YCpc           A//A   | To craft a packet, you have to be a
        scccccp///pSP///p          p//Y   | packet, and learn how to swim in
       sY/////////y  caa           S//P   | the wires and in the waves.
        cayCyayP//Ya              pY/Ya   |        -- Jean-Claude Van Damme
         sY/PsY////YCc          aC//Yp    |
          sc  sccaCY//PCypaapyCP//YSs  
                   spCPY//////YPSps    
                        ccaacs         

 >>> send(IP(dst="8.8.8.8")/ICMP()/"test")
 ERROR: --- Error sending packets
 Traceback (most recent call last):
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 197, in _sndrcv_snd
     self.pks.send(p)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
     return os.write(self.outs, raw(x))
 OSError: [Errno 47] Address family not supported by protocol family
 WARNING: Mac address to reach destination not found. Using broadcast.
 WARNING: Could not get the source MAC: No MAC address found on tun4 !
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 319, in send
     realtime=realtime, return_packets=return_packets)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 291, in __gen_send
     s.send(p)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 362, in send
     L2bpfSocket.send(self, frame)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
     return os.write(self.outs, raw(x))
 OSError: [Errno 47] Address family not supported by protocol family
 >>> 

 >  Taking Scapy's ICMP test cases "Sending an ICMP message at layer 2 and
 >  layer 3" from their test/regression.uts (lines 1337-1344) and running
 >  them manually (without any prior explicit configration of any kind) on
 >  8.2_STABLE/amd64, I get something different:
 >  
 >  >>> send(IP(dst="8.8.8.8")/ICMP(), return_packets=True, realtime=True)
 >  WARNING: Mac address to reach destination not found. Using broadcast.
 >  .
 >  Sent 1 packets.
 >  <PacketList: TCP:0 UDP:0 ICMP:1 Other:0>

 My output is:

 >>> send(IP(dst="8.8.8.8")/ICMP(), return_packets=True, realtime=True)
 ERROR: --- Error sending packets
 Traceback (most recent call last):
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 197, in _sndrcv_snd
     self.pks.send(p)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
     return os.write(self.outs, raw(x))
 OSError: [Errno 47] Address family not supported by protocol family
 WARNING: Mac address to reach destination not found. Using broadcast.
 WARNING: Could not get the source MAC: No MAC address found on tun4 !
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 319, in send
     realtime=realtime, return_packets=return_packets)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 291, in __gen_send
     s.send(p)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 362, in send
     L2bpfSocket.send(self, frame)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
     return os.write(self.outs, raw(x))
 OSError: [Errno 47] Address family not supported by protocol family
 >>> 


 >  >>> sendp(Ether()/IP(dst="8.8.8.8")/ICMP(), return_packets=True,
 >  realtime=True)
 >  WARNING: Mac address to reach destination not found. Using broadcast.
 >  .
 >  Sent 1 packets.
 >  <PacketList: TCP:0 UDP:0 ICMP:1 Other:0>
 >  >>> 
 >  
 >  (In my case, I have a wired wm0 active.)

 My output is:

 >>> sendp(Ether()/IP(dst="8.8.8.8")/ICMP(), return_packets=True, realtime=True)
 ERROR: --- Error sending packets
 Traceback (most recent call last):
   File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 197, in _sndrcv_snd
     self.pks.send(p)
   File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
     return os.write(self.outs, raw(x))
 OSError: [Errno 47] Address family not supported by protocol family
 WARNING: Mac address to reach destination not found. Using broadcast.
 WARNING: Could not get the source MAC: No MAC address found on tun4 !
 .
 Sent 1 packets.
 <PacketList: TCP:0 UDP:0 ICMP:1 Other:0>
 >>> 


 >  > >  > Anyway, you'll want to have a
 >  > >  >  look at the following link in the Scapy documentation:
 >  > >  >  
 >  > > https://scapy.readthedocs.io/en/latest/troubleshooting.html#i-can-t-ping-127-0-0-1-scapy-does-not-work-with-127-0-0-1-or-on-the-loopback-interface
 >  > >  
 >  > >  I tried the above, the result was:
 >  > >  
 >  > >  # scapy
 >  > >  INFO: Can't import matplotlib. Won't be able to plot.
 >  > >  INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
 >  > >  INFO: No IPv6 support in kernel
 >  > >  WARNING: No route found for IPv6 destination :: (no default route?)
 >  > >  INFO: Can't import python-cryptography v1.7+. Disabled WEP
 >  > > decryption/encryption. (Dot11)
 >  > >  INFO: Can't import python-cryptography v1.7+. Disabled IPsec
 >  > > encryption/authentication.
 >  > >  WARNING: IPython not available. Using standard Python shell
 >  > > instead.
 >  > >  AutoCompletion, History are disabled.
 >  > >                                        
 >  > >                       aSPY//YASa       
 >  > >               apyyyyCY//////////YCa       |
 >  > >              sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
 >  > >   ayp ayyyyyyySCP//Pp           syY//C    | Version git-
 >  > > archive.dev304758016
 >  > >   AYAsAYYYYYYYY///Ps              cY//S   |
 >  > >           pCCCCY//p          cSSps y//Y   | 
 >  > > https://github.com/secdev/scapy
 >  > >           SPPPP///a          pP///AC//Y   |
 >  > >                A//A            cyP////C   | Have fun!
 >  > >                p///Ac            sC///a   |
 >  > >                P////YCpc           A//A   | Wanna support scapy?
 >  > > Rate it on
 >  > >         scccccp///pSP///p          p//Y   | sectools!
 >  > >        sY/////////y  caa           S//P   | 
 >  > > http://sectools.org/tool/scapy/
 >  > >         cayCyayP//Ya              pY/Ya   |             -- Satoshi
 >  > > Nakamoto
 >  > >          sY/PsY////YCc          aC//Yp    |
 >  > >           sc  sccaCY//PCypaapyCP//YSs  
 >  > >                    spCPY//////YPSps    
 >  > >                         ccaacs         
 >  > >                                        
 >  > >  >>> conf.L3socket
 >  > >  <L3bpfSocket: read/write packets using BPF>
 >  > >  >>> conf.L3socket=L3RawSocket
 >  > >  >>> conf.L3socket
 >  > >  <L3RawSocket: Layer 3 using Raw sockets (PF_INET/SOCK_RAW)>
 >  > >  >>> p=IP(dst="127.0.0.1")/ICMP()/"test"
 >  > >  >>> p.show2()
 >  > >  ###[ IP ]### 
 >  > >    version= 4
 >  > >    ihl= 5
 >  > >    tos= 0x0
 >  > >    len= 32
 >  > >    id= 1
 >  > >    flags= 
 >  > >    frag= 0
 >  > >    ttl= 64
 >  > >    proto= icmp
 >  > >    chksum= 0x7cda
 >  > >    src= 127.0.0.1
 >  > >    dst= 127.0.0.1
 >  > >    \options\
 >  > >  ###[ ICMP ]### 
 >  > >       type= echo-request
 >  > >       code= 0
 >  > >       chksum= 0x1026
 >  > >       id= 0x0
 >  > >       seq= 0x0
 >  > >  ###[ Raw ]### 
 >  > >          load= 'test'
 >  > >  
 >  > >  >>> send(p)
 >  > >  Traceback (most recent call last):
 >  > >    File "<console>", line 1, in <module>
 >  > >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py",
 >  > > line 316, in send
 >  > >      socket = socket or conf.L3socket(*args, **kargs)
 >  > >    File "/usr/pkg/lib/python3.7/site-packages/scapy/supersocket.py", 
 >  > > line 150, in __init__
 >  > >      self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
 >  > > socket.htons(type))  # noqa: E501
 >  > >  AttributeError: module 'socket' has no attribute 'AF_PACKET'
 >  > >  
 >  > >  >  Separately...
 >  > >  >  
 >  > >  >  >I'd like to clarify the environment of the bug:
 >  > >  >  >(1) I have no active Ethernet or SLIP interfaces;
 >  > >  >  >(2) I have active Wi-Fi and tun interfaces.
 >  > >  >  >
 >  > >  >  >According to the "man 4 bpf": "A packet can be sent out on the network
 >  > >  >  >by writing to a bpf file descriptor. The writes are unbuffered, meaning
 >  > >  >  >only one packet can be processed per write. Currently, only writes to
 >  > >  >  >Ethernets and SLIP links are supported."
 >  > >  >  
 >  > >  >  I think there may be a documentation issue or two there. That last
 >  > >  >  statement is perhaps outdated (I haven't checked in detail), and refers
 >  > >  >  to writes to a link layer which Wi-Fi devices also use. (Note your
 >  > >  >  tcpdump output states your iwi0 device's "link-type" is "Ethernet".)
 >  > >  >  
 >  > >  >  From looking at Scapy commits, it seems NetBSD 8 was the release they
 >  > >  >  developed against. So generally we should expect at minimum it's more
 >  > >  >  likely to work on 8.x than newer releases.
 >  > >  >  
 >  > >  >  I don't use Scapy much; I was using bits of it before for specific
 >  > >  >  purposes, but not most of its functionality, so issues with it haven't
 >  > >  >  been a priority for me to chase. I think in this case some of this
 >  > >  >  issue is better directed to the Scapy project. (I will look into the
 >  > >  >  bpf documentation aspect.)
 >  > >  >  
 >  > >  >  Dave
 >  > >  
 >  > >  OK. I'll write to the Scapy project.
 >  
 >  Once submitted, please add the Scapy issue number to this PR. We'll keep
 >  this open, as it may require something from our end. (Separate from any
 >  NetBSD documentation that needs to be adjusted still.)
 >  
 >  Dave

 OK, but I have not received any answer from the Scapy Project yet.


 --
 Alexei


From: "David H. Gutteridge" <david@gutteridge.ca>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Fri, 17 Jul 2020 18:29:45 -0400

 On Fri, 2020-07-17 at 10:10 +0000, tmp@bh0.amt.ru wrote: 
 >  Yes, I'm sorry, the right output is:
 [...]                          
 >  >>> send(IP(dst="8.8.8.8")/ICMP()/"test")
 >  ERROR: --- Error sending packets
 >  Traceback (most recent call last):
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 197, in _sndrcv_snd
 >      self.pks.send(p)
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
 >      return os.write(self.outs, raw(x))
 >  OSError: [Errno 47] Address family not supported by protocol family
 >  WARNING: Mac address to reach destination not found. Using broadcast.
 >  WARNING: Could not get the source MAC: No MAC address found on tun4 !
 >  Traceback (most recent call last):
 >    File "<console>", line 1, in <module>
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 319, in send
 >      realtime=realtime, return_packets=return_packets)
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 291, in __gen_send
 >      s.send(p)
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 362, in send
 >      L2bpfSocket.send(self, frame)
 >    File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
 >      return os.write(self.outs, raw(x))
 >  OSError: [Errno 47] Address family not supported by protocol family

 Hmm, well, here it has (randomly?) chosen to use tun4, but you may want
 to use your iwi0 interface. There's the "iface" argument for that,
 please see: https://scapy.readthedocs.io/en/latest/usage.html#sending-packets

 Dave


From: tmp@bh0.amt.ru
To: gnats-bugs@netbsd.org, gutteridge@netbsd.org, gnats-admin@netbsd.org,
        pkgsrc-bugs@netbsd.org, tmp@bh0.amt.ru
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Mon, 20 Jul 2020 01:51:45 +0300

 On 07/18/20 01:30, David H. Gutteridge wrote:
 > The following reply was made to PR pkg/55446; it has been noted by GNATS.
 >
 > From: "David H. Gutteridge" <david@gutteridge.ca>
 > To: gnats-bugs@netbsd.org
 > Cc: 
 > Subject: Re: pkg/55446 (scapy function send() does not work)
 > Date: Fri, 17 Jul 2020 18:29:45 -0400
 >
 >  On Fri, 2020-07-17 at 10:10 +0000, tmp@bh0.amt.ru wrote: 
 >  >  Yes, I'm sorry, the right output is:
 >  [...]                          
 >  >  >>> send(IP(dst="8.8.8.8")/ICMP()/"test")
 >  >  ERROR: --- Error sending packets
 >  >  Traceback (most recent call last):
 >  >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 197, in _sndrcv_snd
 >  >      self.pks.send(p)
 >  >    File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
 >  >      return os.write(self.outs, raw(x))
 >  >  OSError: [Errno 47] Address family not supported by protocol family
 >  >  WARNING: Mac address to reach destination not found. Using broadcast.
 >  >  WARNING: Could not get the source MAC: No MAC address found on tun4 !
 >  >  Traceback (most recent call last):
 >  >    File "<console>", line 1, in <module>
 >  >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 319, in send
 >  >      realtime=realtime, return_packets=return_packets)
 >  >    File "/usr/pkg/lib/python3.7/site-packages/scapy/sendrecv.py", line 291, in __gen_send
 >  >      s.send(p)
 >  >    File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 362, in send
 >  >      L2bpfSocket.send(self, frame)
 >  >    File "/usr/pkg/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 317, in send
 >  >      return os.write(self.outs, raw(x))
 >  >  OSError: [Errno 47] Address family not supported by protocol family
 >  
 >  Hmm, well, here it has (randomly?) chosen to use tun4, but you may want
 >  to use your iwi0 interface. There's the "iface" argument for that,
 >  please see: https://scapy.readthedocs.io/en/latest/usage.html#sending-packets
 >  
 >  Dave

 tun4 is the right interface: please look at the e-mail from July, 3 on
 16:35:09 +0300.


 --
 Alexei

From: "David H. Gutteridge" <gutteridge@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55446 CVS commit: pkgsrc/net/scapy
Date: Wed, 18 Aug 2021 01:44:21 +0000

 Module Name:	pkgsrc
 Committed By:	gutteridge
 Date:		Wed Aug 18 01:44:21 UTC 2021

 Modified Files:
 	pkgsrc/net/scapy: Makefile distinfo
 	pkgsrc/net/scapy/patches: patch-scapy_arch_bpf_supersocket.py
 Added Files:
 	pkgsrc/net/scapy/patches: patch-test_bpf.uts

 Log Message:
 scapy: add a patch to fix lo and utun use on Darwin and FreeBSD

 Tested on NetBSD to see if it made a useful difference for an example
 in PR pkg/55446; it does not, but it was more revealing than before.
 Adding in case it's of use for pkgsrc users on those other OSes. (I've
 also added the corresponding test case, in case someone else is curious
 about how this is applied.)


 To generate a diff of this commit:
 cvs rdiff -u -r1.35 -r1.36 pkgsrc/net/scapy/Makefile
 cvs rdiff -u -r1.15 -r1.16 pkgsrc/net/scapy/distinfo
 cvs rdiff -u -r1.4 -r1.5 \
     pkgsrc/net/scapy/patches/patch-scapy_arch_bpf_supersocket.py
 cvs rdiff -u -r0 -r1.1 pkgsrc/net/scapy/patches/patch-test_bpf.uts

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "David H. Gutteridge" <david@gutteridge.ca>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/55446 (scapy function send() does not work)
Date: Fri, 01 Oct 2021 12:33:36 -0400

 Having looked at this a bit more (spurred by a Scapy commit which
 improved things at their end), it seems neither tun nor lo in NetBSD
 will accept packets Scapy outputs via bpf. I tested using lo (I don't
 have a tun setup to work with) and see one problem is that it rejects
 the address family type that bpf associates with the packets. That is,
 they aren't AF_INET or AF_INET6, they end up as pseudo_AF_HDRCMPLT
 type, which gets rejected. There is a similar approach in the tun code,
 though it's a little more generous (it tries to also work with
 AF_UNSPEC), so there, too, packets from Scapy would be rejected.
 FreeBSD had the same approach in its lo until about six years ago, when
 it was fixed. Evidently, FreeBSD's tun still won't work with Scapy
 either (according to the recent notes in the Scapy pull request),
 though Darwin's utun now will.

 I think these are kernel bugs, so I've filed a separate PR (kern/56430)
 with these specifics, and will suspend this PR. (There could still be
 other things that need addressing upstream with Scapy.)

 Separately, you were using i386, which I found had an unrelated issue
 in Scapy code. It was assuming universal 64-bit time offsets when
 evaluating packet headers, when it should be 32 bits for those kinds of
 architectures. I've fixed this in pkgsrc, but haven't had time to
 really test it. (This, like the other item, was really helped by
 FreeBSD people looking at equivalent problems at their end.)

 Dave

State-Changed-From-To: open->suspended
State-Changed-By: gutteridge@NetBSD.org
State-Changed-When: Fri, 01 Oct 2021 16:41:13 +0000
State-Changed-Why:
Suspending until PR kern/56430 is addressed.

From: "David H. Gutteridge" <gutteridge@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55446 CVS commit: src/share/man/man4
Date: Sun, 24 Oct 2021 17:46:07 +0000

 Module Name:	src
 Committed By:	gutteridge
 Date:		Sun Oct 24 17:46:06 UTC 2021

 Modified Files:
 	src/share/man/man4: bpf.4

 Log Message:
 bpf.4: amend caveat about what types of links can be written to

 Try to be clearer about what's supported. A peripheral issue noted in
 PR pkg/55446.


 To generate a diff of this commit:
 cvs rdiff -u -r1.63 -r1.64 src/share/man/man4/bpf.4

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.