Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gv: bind incoming socket to device #779

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

EmmanuelP
Copy link
Contributor

@EmmanuelP EmmanuelP commented Mar 27, 2023

Instead of binding the socket to the interface address, use ADDR_ANY and set the BINDTODEVICE socket option. That would allow to control a device incorrectly configured.

SO_BINDTODEVICE is a linux only feature. May be this is not the right solution.

  • interface
  • device
  • stream

https://aravis-project.discourse.group/t/discover-camera-in-dhcp-mode/598/4

@EmmanuelP EmmanuelP marked this pull request as draft March 27, 2023 08:13
@hackel6
Copy link
Contributor

hackel6 commented Mar 27, 2023

I realize this is a WIP, but i still receive the following:

./arv-tool-0.8 --debug all:3
[16:08:27.949] 🅸 interface> [GvDiscoverSocket::new] Add interface 127.0.0.1 (127.0.0.1)
[16:08:27.949] 🅸 interface> [GvDiscoverSocket::new] Add interface 192.168.1.1 (192.168.1.255)
[16:08:27.949] 🅸 interface> [GvDiscoverSocket::new] Add interface XXX.XXX.XXX.XXX (XXX.XXX.XXX.255)
[16:08:28.950] 🅳 misc> Regex '^.*$' created from glob '*'
No device found

where the last redacted address is our LAN port.
The camera is configured for DHCP and currently has IP assigned: 169.254.160.69

@EmmanuelP
Copy link
Contributor Author

Hi Brian,

Could you check you actually receive a discovery acknowledge packet using wireshark ? Did you try the --gv-allow-broadcast-discovery-ack option ?

@hackel6
Copy link
Contributor

hackel6 commented Mar 28, 2023

Did you try the --gv-allow-broadcast-discovery-ack option ?

I am so sorry. i missed the new flag.
It worked!

./arv-tool-0.8 --debug all:3 --gv-allow-broadcast-discovery-ack
[11:11:21.545] 🅸 interface> [GvDiscoverSocket::new] Add interface 127.0.0.1 (127.0.0.1)
[11:11:21.545] 🅸 interface> [GvDiscoverSocket::new] Add interface 192.168.1.1 (192.168.1.255)
[11:11:21.545] 🅸 interface> [GvDiscoverSocket::new] Add interface XXX.XXX.XXX.XXX (XXX.XXX.XXX.255)
[11:11:21.545] 🅳 cp> packet_type  = ack
                     command      = discovery-ack
                     size         = 248
                     id           = 65535
                     manufacturer = Basler
                     name         = testAviator
                     model        = avA1600-50gmNCG
                     address      = 169.254.160.99
                     00000000 00 00 00 03 00 f8 ff ff 00 01 00 01 80 00 00 01  ................
                     00000010 00 00 00 30 53 14 63 9f 00 00 00 07 00 00 00 06  ...0S.c.........
                     00000020 00 00 00 00 00 00 00 00 00 00 00 00 a9 fe a0 63  ...............c
                     00000030 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00  ................
                     00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
                     00000050 42 61 73 6c 65 72 00 00 00 00 00 00 00 00 00 00  Basler..........
                     00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
                     00000070 61 76 41 31 36 30 30 2d 35 30 67 6d 4e 43 47 00  avA1600-50gmNCG.
                     00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
                     00000090 31 30 35 37 31 31 2d 30 34 00 00 00 00 00 00 00  105711-04.......
                     000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
                     000000b0 6e 6f 6e 65 00 00 00 00 00 00 00 00 00 00 00 00  none............
                     000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
                     000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
                     000000e0 32 31 33 33 36 32 32 33 00 00 00 00 00 00 00 00  21336223........
                     000000f0 74 65 73 74 41 76 69 61 74 6f 72 00 00 00 00 00  testAviator.....
[11:11:21.545] 🅸 interface> [GvInterface::discovery] Device 'Basler-avA1600-50gmNCG-21336223' found (interface 192.168.1.1) user_id 'testAviator' - MAC 'XX:XX:XX:XX:XX:XX'
[11:11:22.547] 🅳 misc> Regex '^.*$' created from glob '*'
Basler-avA1600-50gmNCG-21336223 (169.254.160.99)

Thanks!

@hackel6
Copy link
Contributor

hackel6 commented Mar 28, 2023

Just FYI: i hacked together a dirty version of what would be needed for arvdevice as well, and verified that i could do the following:

> ./arv-tool-0.8 --gv-allow-broadcast-discovery-ack network
Basler-avA1600-50gmNCG-21336223 (169.254.160.99)
Mode: DHCP
Current IP: 169.254.160.99
Current Mask: 255.255.0.0
Current Gateway: 0.0.0.0
Persistent IP: 192.168.1.2
Persistent Mask: 255.255.255.0
Persistent Gateway: 192.168.0.254
> ./arv-tool-0.8 --gv-allow-broadcast-discovery-ack network ip=192.168.1.2 mask=255.255.255.0 gateway=192.168.0.254 mode=PersistentIP
Basler-avA1600-50gmNCG-21336223 (169.254.160.99)

>>>> Power Cycle camera <<<<

> ./arv-tool-0.8 network
Basler-avA1600-50gmNCG-21336223 (192.168.1.2)
Mode: PersistentIP
Current IP: 192.168.1.2
Current Mask: 255.255.255.0
Current Gateway: 192.168.0.254
Persistent IP: 192.168.1.2
Persistent Mask: 255.255.255.0
Persistent Gateway: 192.168.0.254

This new feature will be VERY useful for us when commissioning new cameras or replacing old ones!

@hackel6
Copy link
Contributor

hackel6 commented Jun 14, 2023

Hi Emmanuel,
I'm trying to resurrect this pull request as it would be of great use to my project. However, in doing so, I've noticed that the preliminary changes you've made to arvgvinterface.c actually breaks functionality for our PixeLINK GigE cameras (even the properly-configured ones).
For a PixeLINK camera properly addressed on the same local subnet as the NIC, i get this:

./arv-tool-0.8 --debug all:3
[10:39:17.656] 🅸 interface> [GvDiscoverSocket::new] Add interface 127.0.0.1 (127.0.0.1)
[10:39:17.656] 🅸 interface> [GvDiscoverSocket::new] Add interface XXX.XXX.XXX.XXX (XXX.XXX.255.255)
[10:39:17.656] 🅸 interface> [GvDiscoverSocket::new] Add interface 192.168.1.1 (192.168.1.255)
[10:39:18.658] 🅳 misc> Regex '^.*$' created from glob '*'
No device found

but going back to the old way of binding to the interface_address rather than the any_address allows it work again

g_socket_bind (discover_socket->socket, discover_socket->interface_address, FALSE, &error);

The results:

./arv-tool-0.8 --debug all:3
[10:50:50.093] 🅸 interface> [GvDiscoverSocket::new] Add interface 127.0.0.1 (127.0.0.1)
[10:50:50.093] 🅸 interface> [GvDiscoverSocket::new] Add interface XXX.XXX.XXX.XXX (XXX.XXX.255.255)
[10:50:50.093] 🅸 interface> [GvDiscoverSocket::new] Add interface 192.168.1.1 (192.168.1.255)
[10:50:50.094] 🅳 cp> packet_type  = ack
                     command      = discovery-ack
                     size         = 248
                     id           = 65535
                     manufacturer = PixeLINK Inc.
                     name         =
                     model        = PL-B959G - GEV Camera
                     address      = 192.168.1.3
[10:50:50.094] 🅸 interface> [GvInterface::discovery] Device 'PixeLINK Inc.-PL-B959G - GEV Camera-959xxxxxxxxx' found (interface 192.168.1.1) user_id '' - MAC 'XX:XX:XX:XX:XX:XX'
[10:50:51.095] 🅳 misc> Regex '^.*$' created from glob '*'
PixeLINK Inc.-PL-B959G - GEV Camera-959xxxxxxx (192.168.1.3)

As I stated in the above comments, the changes to interface and device WORKED for discovering the Basler cameras outside the subnet. Any thoughts?

Thanks so much!

@EmmanuelP
Copy link
Contributor Author

Hi Brian,

I probably will not have time to work on this pull request in the near future. But I will happily test a finalized version of this work.

@hackel6
Copy link
Contributor

hackel6 commented Sep 7, 2023

I am revisiting this again and it appears to work but for one major hiccup: SO_BINDTODEVICE is only available to root. I'm not a super strong socket programmer, so i'm not totally sure what SO_BINDTODEVICE is getting us and how this makes things work with broadcast discovery beyond the configured subnet. Also, is the only way to get it working for normal users to enable CAP_NET_RAW in capability.conf??
Thanks!

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.

2 participants