88 "syscall"
99
1010 "github.com/evilsocket/opensnitch/daemon/log"
11- daemonNetlink "github.com/evilsocket/opensnitch/daemon/netlink"
11+ "github.com/evilsocket/opensnitch/daemon/netlink"
1212 "github.com/evilsocket/opensnitch/daemon/netstat"
1313 "github.com/evilsocket/opensnitch/daemon/procmon"
1414 "golang.org/x/sys/unix"
@@ -22,7 +22,7 @@ const (
2222
2323// Socket represents every socket dumped from the kernel for the given filter.
2424type Socket struct {
25- Socket * daemonNetlink .Socket
25+ Socket * netlink .Socket
2626 Iface string
2727 PID int
2828 Mark uint32
@@ -40,6 +40,7 @@ func (pm *SocketsMonitor) dumpSockets() *SocketsTable {
4040 socketList := & SocketsTable {}
4141 socketList .Table = make ([]* Socket , 0 )
4242 socketList .Processes = make (map [int ]* procmon.Process , 0 )
43+
4344 for n , opt := range options {
4445 if exclude (pm .Config .Family , opt .Fam ) {
4546 continue
@@ -48,7 +49,7 @@ func (pm *SocketsMonitor) dumpSockets() *SocketsTable {
4849 continue
4950 }
5051
51- sockList , err := daemonNetlink .SocketsDump (opt .Fam , opt .Proto )
52+ sockList , err := netlink .SocketsDump (opt .Fam , opt .Proto )
5253 if err != nil {
5354 log .Debug ("[sockmon][%d] fam: %d, proto: %d, error: %s" , n , opt .Fam , opt .Proto , err )
5455 continue
@@ -73,6 +74,26 @@ func (pm *SocketsMonitor) dumpSockets() *SocketsTable {
7374 wg .Wait ()
7475 }
7576
77+ if ! exclude (pm .Config .Family , unix .AF_XDP ) && ! exclude (pm .Config .Proto , syscall .IPPROTO_RAW ) {
78+ xdpList , err := netlink .SocketGetXDP ()
79+ if err == nil {
80+ var wg sync.WaitGroup
81+ for _ , xdp := range xdpList {
82+ s := netlink.Socket {}
83+ s .Family = unix .AF_XDP
84+ s .INode = uint32 (xdp .XDPDiagMsg .Ino )
85+ s .UID = uint32 (xdp .XDPInfo .UID )
86+ s .ID = netlink.SocketID {
87+ Interface : xdp .XDPInfo .Ifindex ,
88+ Cookie : xdp .XDPDiagMsg .Cookie ,
89+ }
90+ wg .Add (1 )
91+ go addSocketToTable (pm .Ctx , & wg , syscall .IPPROTO_RAW , socketList , s )
92+ }
93+ wg .Wait ()
94+ }
95+ }
96+
7697 if exclude (pm .Config .Family , unix .AF_PACKET ) {
7798 return socketList
7899 }
@@ -90,11 +111,11 @@ func (pm *SocketsMonitor) dumpSockets() *SocketsTable {
90111 pktList [n ] = struct {}{}
91112
92113 wg .Add (1 )
93- s := daemonNetlink .Socket {}
114+ s := netlink .Socket {}
94115 s .Family = unix .AF_PACKET
95116 s .INode = uint32 (e .INode )
96117 s .UID = uint32 (e .UserId )
97- s .ID = daemonNetlink .SocketID {
118+ s .ID = netlink .SocketID {
98119 Interface : uint32 (e .Iface ),
99120 }
100121 // TODO: report the protocol and type
@@ -109,7 +130,7 @@ func exclude(expected, what uint8) bool {
109130 return expected > AnySocket && expected != what
110131}
111132
112- func addSocketToTable (ctx context.Context , wg * sync.WaitGroup , proto uint8 , st * SocketsTable , s daemonNetlink .Socket ) {
133+ func addSocketToTable (ctx context.Context , wg * sync.WaitGroup , proto uint8 , st * SocketsTable , s netlink .Socket ) {
113134 inode := int (s .INode )
114135 pid := procmon .GetPIDFromINode (inode , fmt .Sprint (inode ,
115136 s .ID .Source , s .ID .SourcePort , s .ID .Destination , s .ID .DestinationPort ),
0 commit comments