Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
/ nsmock Public

net-stat-mock. A Linux kernel module for mocking stats on a network device

Notifications You must be signed in to change notification settings

B0nBun/nsmock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetStatMock

This is a Linux kernel module which allows you to manually change the stats on it's network device. I couldn't find any other reliable and easy way to "simulate" error packets, dropped packets or other kinds of stats, so I decided to do this instead.

Build

Build can be done using make, everything generated by the kernel build-system will be in the output directory

$ make
$ ls ./output | grep .ko
nsmock.ko

Usage

NOTE: Writing to sysfs files can only be done by root

$ insmod output/nsmock.ko
$ ifconfig nsmock0
nsmock0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:00:00:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
$ ls /sys/kernel/nsmock/ # All of the available stats will be in the sysfs directory
collisions     rx_dropped        rx_missed_errors   tx_carrier_errors  tx_heartbeat_errors
multicast      rx_errors         rx_over_errors     tx_compressed      tx_packets
rx_bytes       rx_fifo_errors    rx_packets         tx_dropped         tx_window_errors
rx_compressed  rx_frame_errors   tx_aborted_errors  tx_errors
rx_crc_errors  rx_length_errors  tx_bytes           tx_fifo_errors
$ echo 10 > /sys/kernel/nsmock/rx_packets # Setting the stat
$ echo 1000 > /sys/kernel/nsmock/rx_bytes 
$ echo +500 > /sys/kernel/nsmock/rx_bytes # Incrementing
$ echo -250 > /sys/kernel/nsmock/rx_bytes # Decrement
$ ifconfig nsmock0
nsmock0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:00:00:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 10  bytes 1250 (1.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

About

net-stat-mock. A Linux kernel module for mocking stats on a network device

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published