Skip to content

Conversation

@m-dilorenzi
Copy link
Collaborator

This pull request enhances the network scanning functionality by adding subnet size validation and improving interface information. The most important changes are:

Network scanning improvements:

  • Updated the scan function to take both device and interface parameters, and added logic to block ARP scans on subnets smaller than /20, returning a validation error if the subnet is too large.
  • Added the netmask_to_cidr_notation helper function to convert a netmask (e.g., 255.255.0.0) into CIDR notation (e.g., 16), using the ipaddress module.

Interface listing enhancements:

  • Modified the list_interfaces function to include the netmask in CIDR notation for each interface in its output.

Command-line interface updates:

  • Updated the command-line argument handling to require and pass the interface parameter for scans, ensuring the new validation logic is used.

Refs: #1434

@m-dilorenzi m-dilorenzi requested a review from Tbaile January 28, 2026 11:57
@m-dilorenzi m-dilorenzi self-assigned this Jan 28, 2026
Comment on lines 48 to 59
def scan(device, interface):
ret = []
u = EUci()

if interface:
netmask = u.get('network', interface, 'netmask')
netmask_cidr = netmask_to_cidr_notation(netmask)

# block arp-scan if the subnet is /19 or smaller
if netmask_cidr is not None and netmask_cidr < 20:
return utils.validation_error("subnet_too_large_for_scan")

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Tbaile Tbaile linked an issue Jan 29, 2026 that may be closed by this pull request
Copy link
Member

@gsanchietti gsanchietti left a comment

Choose a reason for hiding this comment

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

Since you're already executing the code in a try/except, you get rif of the netmask_to_cidr notation function

try:
interface = utils.get_interface_from_device(u, device)
netmask = u.get('network', interface, 'netmask')
netmask_cidr = netmask_to_cidr_notation(netmask)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
netmask_cidr = netmask_to_cidr_notation(netmask)
netmask_cidr = ipaddress.IPv4Network(f'0.0.0.0/{netmask}').prefixlen

@m-dilorenzi m-dilorenzi marked this pull request as draft February 3, 2026 09:47
@m-dilorenzi
Copy link
Collaborator Author

It’s best to use ip -j address to determine the network netmask. This approach also lets you handle interfaces that aren’t statically configured (ex. DHCP, OpenVPN tunnels, etc.), for which the netmask can’t be retrieved via UCI because it isn’t explicitly configured there.

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.

network scan fails when using very large subnets

4 participants