Skip to content

Commit

Permalink
Support routers that only provide WANIPService:2
Browse files Browse the repository at this point in the history
InternetGatewayDevice:2 adds WANConnectionDevice:2 as a sub-device
that implements WANIPConnection:2 instead of WANIPConnection:1.

This provides the same methods as WANIPConnection:1 but has some
additional constraints such as the gateway must only serve it on the
LAN interface and should reject mappings to an address that wasn't the
origin of the request.
  • Loading branch information
fishface60 committed Dec 27, 2024
1 parent b095458 commit 56317fa
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ public class PortMappingListener extends DefaultRegistryListener {

private final Logger logger = LoggerFactory.getLogger(PortMappingListener.class);

public static final DeviceType IGD_DEVICE_TYPE = new UDADeviceType("InternetGatewayDevice", 1);
public static final DeviceType CONNECTION_DEVICE_TYPE = new UDADeviceType("WANConnectionDevice", 1);
public static final DeviceType IGD_DEVICE_TYPE_V1 = new UDADeviceType("InternetGatewayDevice", 1);
public static final DeviceType IGD_DEVICE_TYPE_V2 = new UDADeviceType("InternetGatewayDevice", 2);
public static final DeviceType CONNECTION_DEVICE_TYPE_V1 = new UDADeviceType("WANConnectionDevice", 1);
public static final DeviceType CONNECTION_DEVICE_TYPE_V2 = new UDADeviceType("WANConnectionDevice", 2);

public static final ServiceType IP_SERVICE_TYPE = new UDAServiceType("WANIPConnection", 1);
public static final ServiceType IP_SERVICE_TYPE_V1 = new UDAServiceType("WANIPConnection", 1);
public static final ServiceType IP_SERVICE_TYPE_V2 = new UDAServiceType("WANIPConnection", 2);
public static final ServiceType PPP_SERVICE_TYPE = new UDAServiceType("WANPPPConnection", 1);

protected PortMapping[] portMappings;
Expand Down Expand Up @@ -199,27 +202,37 @@ public void failure(ActionInvocation invocation, UpnpResponse operation, String
}

protected Service<?, ?> discoverConnectionService(Device<?, ?, ?> device) {
if (!device.getType().equals(IGD_DEVICE_TYPE)) {
DeviceType deviceType = device.getType();
if (!deviceType.equals(IGD_DEVICE_TYPE_V1) && !deviceType.equals(IGD_DEVICE_TYPE_V2)) {
return null;
}

Device<?, ?, ?>[] connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE);
Device<?, ?, ?>[] connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE_V2);
if (connectionDevices.length == 0) {
logger.debug("IGD doesn't support '{}': {}", CONNECTION_DEVICE_TYPE, device);
logger.debug("IGD doesn't support '{}': {}", CONNECTION_DEVICE_TYPE_V2, device);
connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE_V1);
}
if (connectionDevices.length == 0) {
logger.debug("IGD doesn't support '{}': {}", CONNECTION_DEVICE_TYPE_V1, device);
return null;
}

Device<?, ?, ?> connectionDevice = connectionDevices[0];
logger.debug("Using first discovered WAN connection device: {}", connectionDevice);

Service<?, ?> ipConnectionService = connectionDevice.findService(IP_SERVICE_TYPE);
Service<?, ?> pppConnectionService = connectionDevice.findService(PPP_SERVICE_TYPE);
Service<?, ?> connectionService = connectionDevice.findService(IP_SERVICE_TYPE_V2);
if (connectionService == null) {
connectionService = connectionDevice.findService(IP_SERVICE_TYPE_V1);
}
if (connectionService == null) {
connectionService = connectionDevice.findService(PPP_SERVICE_TYPE);
}

if (ipConnectionService == null && pppConnectionService == null) {
if (connectionService == null) {
logger.debug("IGD doesn't support IP or PPP WAN connection service: {}", device);
}

return ipConnectionService != null ? ipConnectionService : pppConnectionService;
return connectionService;
}

protected void handleFailureMessage(String s) {
Expand Down

0 comments on commit 56317fa

Please sign in to comment.