Opened 9 years ago

Closed 9 years ago

#3206 closed defect (fixed)

serverip isn't used for all services

Reported by: FME Owned by:
Priority: minor Component: Protocol - CCCam
Severity: low Keywords:
Cc: FME Sensitive: no

Description

Revision

8415

Issue Description

ip address (serverip) specified in oscam.conf. And oscam is listening on this ip AND on others...
CCcam is only listening on the "serverip", but http-server is bind to all ips.
The problem is, that the outgoing cccam connections should go out with the "serverip" as source ip.
I have two interfaces: eth0 -> 192.168.1.2 and eth0:0 192.168.1.4
oscam should listen only on 192.168.1.4 as specified in the oscam.conf and outgoing connections should go out with the 192.168.1.4 ip address, but they are made with the 192.168.1.2 ip address as source.

When the issue occurs

everytime

How the issue is reproducable

you need two oscam instances and two network interfaces.
e.g. eth0 and eth0:0 with different ip addresses.
bind oscam to the ip address of eth0:0 and create a reader on this instance to the ip address of eth0. In the oscam instance with the ip address of eth0 you see a client with the ip address of eth0 instead of eth0:0.

Attachments (4)

oscam.log (1.6 KB ) - added by FME 9 years ago.
oscam-reader.c.diff (1.1 KB ) - added by gf 9 years ago.
You just copied the code that is above the patch can be like this.
serverip-bind.patch (1.7 KB ) - added by gf 9 years ago.
Better patch, with swebif support. Now serverip in [global] works as expected.
ipv6_bind.diff (2.9 KB ) - added by manio 9 years ago.

Download all attachments as: .zip

Change History (17)

by FME, 9 years ago

Attachment: oscam.log added

comment:1 by FME, 9 years ago

Cc: FME added
Component: Please fill inProtocol - CCCam
Priority: Please fill inminor
Severity: Please fill inlow

comment:2 by FME, 9 years ago

I found a solution for using the right source ip address.
In oscam-reader.c startin from line 312 you need to add:

else {
		memset((char *)&loc_sa,0,sizeof(loc_sa));
		loc_sa.sin_family = AF_INET;
		if (IP_ISSET(cfg.srvip))
			IP_ASSIGN(SIN_GET_ADDR(loc_sa), cfg.srvip);
		else
			loc_sa.sin_addr.s_addr = INADDR_ANY;

		if (bind(client->udp_fd, (struct sockaddr *)&loc_sa, sizeof (loc_sa))<0) {
			rdr_log(rdr, "bind for source address using failed (errno=%d %s)", errno, strerror(errno));
			close(client->udp_fd);
			client->udp_fd = 0;
			block_connect(rdr);
			return -1;
		}
	}

Then the ip address in the oscam.conf is used as source ip address for outgoing connections.

Can somebody add that in the official oscam source? Or how can i add it?

comment:3 by gf, 9 years ago

Please attach a patch, because now it is not clear what you are adding/changing and where.

comment:4 by FME, 9 years ago

Okay, i hope this is correct:

Index: oscam-reader.c
===================================================================
--- oscam-reader.c	(revision 8469)
+++ oscam-reader.c	(working copy)
@@ -309,7 +309,23 @@
 			return -1;
 		}
 	}
+	else {
+		memset((char *)&loc_sa,0,sizeof(loc_sa));
+		loc_sa.sin_family = AF_INET;
+		if (IP_ISSET(cfg.srvip))
+			IP_ASSIGN(SIN_GET_ADDR(loc_sa), cfg.srvip);
+		else
+			loc_sa.sin_addr.s_addr = INADDR_ANY;
 
+		if (bind(client->udp_fd, (struct sockaddr *)&loc_sa, sizeof (loc_sa))<0) {
+			rdr_log(rdr, "bind for source address using failed (errno=%d %s)", errno, strerror(errno));
+			close(client->udp_fd);
+			client->udp_fd = 0;
+			block_connect(rdr);
+			return -1;
+		}
+	}
+
 #ifdef IPV6SUPPORT
 	if (IN6_IS_ADDR_V4MAPPED(&rdr->client->ip) || IN6_IS_ADDR_V4COMPAT(&rdr->client->ip)) {
 		((struct sockaddr_in *)(&client->udp_sa))->sin_family = AF_INET;

by gf, 9 years ago

Attachment: oscam-reader.c.diff added

You just copied the code that is above the patch can be like this.

by gf, 9 years ago

Attachment: serverip-bind.patch added

Better patch, with swebif support. Now serverip in [global] works as expected.

comment:5 by gf, 9 years ago

Resolution: fixed
Status: newclosed

Fixed in r8515.

comment:6 by manio, 9 years ago

Resolution: fixed
Status: closedreopened

Hi guys,
When connecting to IPv6 servers, I've got in the log:

bind failed (errno=22 Invalid argument)

I'm attaching the patch which disables this bind when IPv6 is enabled.

comment:7 by Admin, 9 years ago

And why should it be disabled just whenever the binary is compiled with IPv6? I don't think this is the correct solution. Isn't the problem just that we need something like that (sorry can't test as I don't use ipv6)

#ifdef IPV6SUPPORT
if (!cfg.srvip || (!IN6_IS_ADDR_V4MAPPED(cfg.srvip) && !IN6_IS_ADDR_V4COMPAT(cfg.srvip))
	loc_sa.sin_family = AF_INET6;
#endif

below

loc_sa.sin_family = AF_INET;

comment:8 by gf, 9 years ago

The patch was kind of hack - that is true. It can be fixed but since I too don't use IPv6 it was easier to fix the breakage than fix it properly...

comment:9 by Admin, 9 years ago

I didn't mean your patch but the one from manio above my post ;)

comment:10 by manio, 9 years ago

Admin,
Your fix was not proper, but it inspired me to create a better version of my patch. For me the bind is now working with IPv4 as well as IPv6. Please review and test.

comment:11 by gf, 9 years ago

You have to remove the #ifdefs added in r8570.

by manio, 9 years ago

Attachment: ipv6_bind.diff added

comment:12 by manio, 9 years ago

True. Patch updated.

comment:13 by gf, 9 years ago

Resolution: fixed
Status: reopenedclosed

Committed r8574.

Note: See TracTickets for help on using tickets.