Skip to content

feat: support to parse enip and cip protocols for industrial automation#137

Merged
mosajjal merged 4 commits intogopacket:masterfrom
dreadl0ck:feature/cip-and-enip-support
Nov 2, 2025
Merged

feat: support to parse enip and cip protocols for industrial automation#137
mosajjal merged 4 commits intogopacket:masterfrom
dreadl0ck:feature/cip-and-enip-support

Conversation

@dreadl0ck
Copy link
Copy Markdown
Contributor

Patch Set Summary: Industrial Protocol Support (CIP, Ethernet/IP)

Overview

This patch set ports the changes from google/gopacket PR #758 to add support for industrial automation protocols: CIP (Common Industrial Protocol), and ENIP (Ethernet/IP).

New Protocol Implementations

1. CIP (Common Industrial Protocol)

File: layers/cip.go

  • Purpose: Application-layer protocol used in industrial automation
  • Key Features:
    • Service code definitions (GetAttributesAll, SetAttributesAll, GetAttributeSingle, SetAttributeSingle, MultipleServicePacket)
    • Status code handling (Success, ConnectionFailure, ResourceUnavailable, etc.)
    • Path segment parsing for Class ID, Instance ID, and Attribute ID
    • Request/Response differentiation
    • Full decoder implementation following gopacket patterns

2. ENIP (Ethernet/IP)

File: layers/enip.go

  • Purpose: Ethernet encapsulation protocol for CIP
  • Key Features:
    • 24-byte header parsing
    • Command codes (NOP, ListServices, RegisterSession, UnregisterSession, SendRRData, SendUnitData, etc.)
    • Status code handling
    • Session management fields (SessionHandle, SenderContext)
    • Automatic CIP payload decoding for SendRRData and SendUnitData commands
    • Serialization support
    • Little-endian encoding (as per ENIP specification)

Modified Files

Core Layer Registration

layers/layertypes.go

  • Added LayerTypeENIP (ID: 151)
  • Added LayerTypeCIP (ID: 152)
LayerTypeENIP = gopacket.RegisterLayerType(151, gopacket.LayerTypeMetadata{
    Name: "ENIP", 
    Decoder: gopacket.DecodeFunc(decodeENIP)
})
LayerTypeCIP = gopacket.RegisterLayerType(152, gopacket.LayerTypeMetadata{
    Name: "CIP", 
    Decoder: gopacket.DecodeFunc(decodeCIP)
})

layers/ports.go

Added port mappings for automatic protocol detection:

TCP Ports:

  • Port 2222 → LayerTypeENIP (EtherNet/IP-1)
  • Port 44818 → LayerTypeENIP (EtherNet/IP-2)

UDP Ports:

  • Port 2222 → LayerTypeENIP (EtherNet/IP-1)
  • Port 44818 → LayerTypeENIP (EtherNet/IP-2)

layers/enums.go

  • Added missing errors import
  • Added EthernetTypeERSPAN constant (0x88be)
  • Added EthernetTypeRaw constant (0xFFFF)

Protocol Specifications

Port Numbers

Protocol TCP Port UDP Port Description
ENIP 2222 2222 EtherNet/IP-1 (standard)
ENIP 44818 44818 EtherNet/IP-2 (alternate)

Layer Hierarchy

Ethernet
  └── IPv4/IPv6
      └── TCP/UDP
          └── ENIP (ports 2222, 44818)
              └── CIP (for SendRRData/SendUnitData commands)
                  └── Payload

Credits

References

  • CIP: ODVA Common Industrial Protocol specification
  • ENIP: ODVA Ethernet/IP specification
  • IANA Ports: Port 2222 (EtherNet-IP-1), Port 44818 (EtherNet-IP-2)

@mosajjal mosajjal requested a review from Copilot October 25, 2025 05:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for industrial automation protocols CIP (Common Industrial Protocol) and ENIP (Ethernet/IP) by porting implementations from google/gopacket PR #758. The changes enable packet capture and analysis of industrial control system communications commonly used in manufacturing and automation environments.

Key Changes:

  • Implementation of CIP and ENIP protocol layers with full decoding support
  • Registration of new layer types and port mappings for automatic protocol detection
  • Addition of EthernetTypeRaw constant for special IP handling

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
layers/enip.go New ENIP protocol decoder with command/status handling and CIP payload support
layers/cip.go New CIP protocol decoder with service codes, path segment parsing, and request/response differentiation
layers/layertypes.go Registration of LayerTypeENIP (151) and LayerTypeCIP (152)
layers/ports.go TCP/UDP port mappings for ports 2222 and 44818 to ENIP layer
layers/enums.go Addition of EthernetTypeERSPAN and EthernetTypeRaw constants
INDUSTRIAL_PROTOCOLS_PATCH.md Documentation of protocol implementations and specifications

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mosajjal and others added 3 commits November 2, 2025 17:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mosajjal mosajjal merged commit ac0316a into gopacket:master Nov 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants