Skip to contentSkip to conversation

ss: move to its own directory and split up ss.c

PATCH In review Stephen Hemminger 3 participants 3 messages Nov 19 – Nov 24

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ss: move to its own directory and split up ss.c

The ss command has grown over time and was a single large file. Move it and its filter parser to ss/ with their own Makefile, and split ss.c by function:

  ss.h        shared types, option flags and prototypes
  ss.c        main() and option parsing
  output.c    column layout and buffered output
  sock.c      output common to all socket families
  filter.c    socket selection and filter expressions
  users.c     socket owners and SELinux contexts from /proc
  service.c   port to service name resolution
  inet.c      inet_diag dumps, kill and TCPDIAG_FILE replay
  tcp.c       TCP, TLS and MPTCP details
  sctp.c      SCTP details
  bpf.c       BPF socket-local storage

unix.c, packet.c, xdp.c, netlink.c, vsock.c, tipc.c
one file per socket family
events.c -E event monitoring
summary.c -s summary

---
 Makefile                      |    2 +-
 misc/Makefile                 |    6 +-
 misc/ss.c                     | 5845 ---------------------------------
 ss/.gitignore                 |    2 +
 ss/Makefile                   |   21 +
 ss/bpf.c                      |  337 ++
 ss/events.c                   |   95 +
 ss/filter.c                   |  927 ++++++
 ss/inet.c                     |  580 ++++
 ss/netlink.c                  |  205 ++
 ss/output.c                   |  529 +++
 ss/packet.c                   |  216 ++
 ss/sctp.c                     |  140 +
 ss/service.c                  |  246 ++
 ss/sock.c                     |  276 ++
 ss/ss.c                       |  603 ++++
 ss/ss.h                       |  386 +++
 ss/ss_util.h                  |   23 +
 ss/ssfilter.h                 |   34 +
 ss/ssfilter.y                 |  369 +++
 ss/ssfilter_check.c           |  104 +
 ss/summary.c                  |  167 +
 ss/tcp.c                      |  623 ++++
 ss/tipc.c                     |  119 +
 ss/unix.c                     |  140 +
 ss/users.c                    |  333 ++
 ss/vsock.c                    |   87 +
 ss/xdp.c                      |  170 +
 testsuite/Makefile            |    2 +-
 testsuite/tests/ss/ssfilter.t |    2 +-
 30 files changed, 6736 insertions(+), 5853 deletions(-)
 delete mode 100644 misc/ss.c
 create mode 100644 ss/.gitignore
 create mode 100644 ss/Makefile
 create mode 100644 ss/bpf.c
 create mode 100644 ss/events.c
 create mode 100644 ss/filter.c
 create mode 100644 ss/inet.c
 create mode 100644 ss/netlink.c
 create mode 100644 ss/output.c
 create mode 100644 ss/packet.c
 create mode 100644 ss/sctp.c
 create mode 100644 ss/service.c
 create mode 100644 ss/sock.c
 create mode 100644 ss/ss.c
 create mode 100644 ss/ss.h
 create mode 100644 ss/ss_util.h
 create mode 100644 ss/ssfilter.h
 create mode 100644 ss/ssfilter.y
 create mode 100644 ss/ssfilter_check.c
 create mode 100644 ss/summary.c
 create mode 100644 ss/tcp.c
 create mode 100644 ss/tipc.c
 create mode 100644 ss/unix.c
 create mode 100644 ss/users.c
 create mode 100644 ss/vsock.c
 create mode 100644 ss/xdp.c
Makefile +1 -1
index 6e4e6a85..d3755305 100644
@@ -55,7 +55,7 @@ WFLAGS += -Wmissing-declarations -Wold-style-definition -Wformat=2
 CFLAGS := $(WFLAGS) $(CCOPTS) -I../include -I../include/uapi $(DEFINES) $(CFLAGS)
 YACCFLAGS = -d -t -v
 
-SUBDIRS=lib ip tc bridge misc netem genl man
+SUBDIRS=lib ip tc bridge misc ss netem genl man
 ifeq ($(HAVE_MNL),y)
 SUBDIRS += tipc devlink rdma dcb vdpa netshaper dpll
 endif
misc/Makefile +1 -5
index 4736d928..8c569ab8 100644
@@ -1,16 +1,12 @@
 # SPDX-License-Identifier: GPL-2.0
-SSOBJ=ss.o ssfilter_check.o ssfilter.tab.o
 LNSTATOBJ=lnstat.o lnstat_util.o
 
-TARGETS=ss nstat ifstat rtacct lnstat
+TARGETS=nstat ifstat rtacct lnstat
 
 include ../config.mk
 
 all: $(TARGETS)
 
-ss: $(SSOBJ)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
-
 nstat: nstat.c
 	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o nstat nstat.c $(LDLIBS) -lm
 
misc/ss.c deleted +0 -5845

2,975 lines not on this page · raw message

ss/.gitignore new file +2 -0
new file mode 100644
index 00000000..650c3739

Lines of this file are not shown. View the raw message.

ss/Makefile new file +21 -0
new file mode 100644
index 00000000..364af87a

Lines of this file are not shown. View the raw message.

ss/bpf.c new file +337 -0

337 lines not on this page · raw message

ss/events.c new file +95 -0

95 lines not on this page · raw message

ss/filter.c new file +927 -0

927 lines not on this page · raw message

ss/inet.c new file +580 -0

580 lines not on this page · raw message

ss/netlink.c new file +205 -0

205 lines not on this page · raw message

ss/output.c new file +529 -0

529 lines not on this page · raw message

ss/packet.c new file +216 -0

216 lines not on this page · raw message

ss/sctp.c new file +140 -0

140 lines not on this page · raw message

ss/service.c new file +246 -0

246 lines not on this page · raw message

ss/sock.c new file +276 -0

276 lines not on this page · raw message

ss/ss.c new file +603 -0

603 lines not on this page · raw message

ss/ss.h new file +386 -0

386 lines not on this page · raw message

ss/ss_util.h new file +23 -0
new file mode 100644
index 00000000..37936c66

Lines of this file are not shown. View the raw message.

ss/ssfilter.h new file +34 -0
new file mode 100644
index 00000000..73e55e04

Lines of this file are not shown. View the raw message.

ss/ssfilter.y new file +369 -0

369 lines not on this page · raw message

ss/ssfilter_check.c new file +104 -0

104 lines not on this page · raw message

ss/summary.c new file +167 -0

167 lines not on this page · raw message

ss/tcp.c new file +623 -0

623 lines not on this page · raw message

ss/tipc.c new file +119 -0

119 lines not on this page · raw message

ss/unix.c new file +140 -0

140 lines not on this page · raw message

ss/users.c new file +333 -0

333 lines not on this page · raw message

ss/vsock.c new file +87 -0

87 lines not on this page · raw message

ss/xdp.c new file +170 -0

170 lines not on this page · raw message

testsuite/Makefile +1 -1
index 82f3f98c..70120594 100644

Lines of this file are not shown. View the raw message.

testsuite/tests/ss/ssfilter.t +1 -1
index cc0f01a5..b3fdab02 100755

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.53.0

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 15 lines · Stephen Hemminger

The ss command has grown over time and was a single large file. Move it and its filter parser to ss/ with their own Makefile, and split ss.c by function:

  ss.h        shared types, option flags and prototypes
  ss.c        main() and option parsing
  output.c    column layout and buffered output
  sock.c      output common to all socket families
  filter.c    socket selection and filter expressions
  users.c     socket owners and SELinux contexts from /proc
  service.c   port to service name resolution
  inet.c      inet_diag dumps, kill and TCPDIAG_FILE replay
  tcp.c       TCP, TLS and MPTCP details
  sctp.c      SCTP details
  bpf.c       BPF socket-local storage
Quoted 7 lines

unix.c, packet.c, xdp.c, netlink.c, vsock.c, tipc.c
one file per socket family
events.c -E event monitoring
summary.c -s summary

---

does not apply to top of tree

maintainer
#2 lore raw
In reply to Stephen Hemminger

Hi Stephen,

Quoted 15 lines · Stephen Hemminger

The ss command has grown over time and was a single large file. Move it and its filter parser to ss/ with their own Makefile, and split ss.c by function:

  ss.h        shared types, option flags and prototypes
  ss.c        main() and option parsing
  output.c    column layout and buffered output
  sock.c      output common to all socket families
  filter.c    socket selection and filter expressions
  users.c     socket owners and SELinux contexts from /proc
  service.c   port to service name resolution
  inet.c      inet_diag dumps, kill and TCPDIAG_FILE replay
  tcp.c       TCP, TLS and MPTCP details
  sctp.c      SCTP details
  bpf.c       BPF socket-local storage
Quoted 4 lines

unix.c, packet.c, xdp.c, netlink.c, vsock.c, tipc.c
one file per socket family
events.c -E event monitoring
summary.c -s summary

Good idea to split ss.c!

Quoted 25 lines
---
 Makefile                      |    2 +-
 misc/Makefile                 |    6 +-
 misc/ss.c                     | 5845 ---------------------------------
 ss/.gitignore                 |    2 +
 ss/Makefile                   |   21 +
 ss/bpf.c                      |  337 ++
 ss/events.c                   |   95 +
 ss/filter.c                   |  927 ++++++
 ss/inet.c                     |  580 ++++
 ss/netlink.c                  |  205 ++
 ss/output.c                   |  529 +++
 ss/packet.c                   |  216 ++
 ss/sctp.c                     |  140 +
 ss/service.c                  |  246 ++
 ss/sock.c                     |  276 ++
 ss/ss.c                       |  603 ++++
 ss/ss.h                       |  386 +++
 ss/ss_util.h                  |   23 +
 ss/ssfilter.h                 |   34 +
 ss/ssfilter.y                 |  369 +++
 ss/ssfilter_check.c           |  104 +
 ss/summary.c                  |  167 +
 ss/tcp.c                      |  623 ++++
Quoted 8 lines
 ss/tipc.c                     |  119 +
 ss/unix.c                     |  140 +
 ss/users.c                    |  333 ++
 ss/vsock.c                    |   87 +
 ss/xdp.c                      |  170 +
 testsuite/Makefile            |    2 +-
 testsuite/tests/ss/ssfilter.t |    2 +-
 30 files changed, 6736 insertions(+), 5853 deletions(-)

I was surprised that you ended up with ~900 more lines, but I think you missed the removal of misc/ssfilter* files.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.