A robotkernel module that creates a raw socket (SOCK_RAW) on a specified network interface and exposes it as a robotkernel stream device. This module provides low-level access to raw Ethernet frames, enabling direct packet capture and transmission for custom protocols, industrial communication, and network debugging.
- Creates a
SOCK_RAWsocket on a specified Ethernet interface - Exposes raw Ethernet frames via robotkernel stream interface
- Supports configurable receive timeouts
- Real-time capable with configurable thread priority and CPU affinity
- Configurable via YAML for easy integration
- Compatible with robotkernel architecture
- Ideal for EtherCAT, PROFINET, custom protocols, and network monitoring
The module opens a raw socket on the specified network interface and reads and writes raw Ethernet frames. These frames are then exposed as a robotkernel stream device, allowing other modules to process them in real-time. The module handles the low-level socket operations and provides a clean interface for higher-level protocol handlers.
- Root privileges OR the
CAP_NET_RAWcapability - The
grant_cap_net_rawkernel module by Florian Schmidt (openethercat) can be used to grant the required capability without root access
The module is configured via a YAML configuration file. Below is an example configuration:
# Configuration file for module_sock_raw.
#
# vi: set ft=yaml nowrap:
# -*- mode: yaml -*-
#########################################################
# network interface settings
# Defines the ethernet interface name to open.
ifname: eth0
# Sets the receive timeout in nanoseconds.
recv_timeout_ns: 1000000
# Protocols to listen on.
# protocol: 0xA488
#########################################################
# logging settings
# Standard robotkernel module local loglevel.
# loglevel: verbose| Parameter | Description | Default | Example |
|---|---|---|---|
ifname |
The Ethernet interface name to open (e.g., eth0, enp3s0) | required | eth0 |
recv_timeout_ns |
Receive timeout in nanoseconds (0 = no timeout) | 1000000 (1ms) |
500000 (500μs) |
protocol |
Specific protocol to filter (e.g., 0xA488 for EtherCAT) | none | 0xA488 |
loglevel |
Logging verbosity (optional) | info |
verbose |
-
Clone the repository:
git clone https://github.com/robotkernel-hal/module_sock_raw.git cd module_sock_raw -
Build the module:
./bootstrap.sh autoreconf -if ./configure make -j$(nproc) -
Install the module:
sudo make install
-
Ensure robotkernel is properly configured to load the module.
- Start robotkernel with the module loaded.
- Configure the module using the provided YAML configuration.
- The module will open a raw socket on the specified interface and expose it as a stream device.
- Use the stream device (e.g.,
sock-raw-2-stream.sock_raw.stream) with other modules likemodule_eslfor protocol processing. - For production use, consider using
grant_cap_net_rawto grantCAP_NET_RAWcapability without root privileges.
- robotkernel HAL framework
- autotools
- Linux kernel with real-time capabilities (PREEMPT_RT recommended)
- Root privileges or
CAP_NET_RAWcapability for raw socket access
Raw socket access is a privileged operation. Use one of the following approaches:
- Run as root (not recommended for production)
- Grant
CAP_NET_RAWcapability usinggrant_cap_net_raw(recommended):sudo insmod grant_cap_net_raw.ko
Contributions are welcome! Please follow the standard pull request workflow:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a pull request
This project is licensed under the LGPL-V3 License - see the LICENSE file for details.
For questions, issues, or feature requests, please open an issue on GitHub or contact the maintainers.
Note: Raw socket access requires elevated privileges. Use grant_cap_net_raw (by Florian Schmidt) to grant the CAP_NET_RAW capability without running as root. Always follow security best practices when working with raw network access.