Feature/bacnet ipv6 bind interface for link local comunication (#359)
This commit is contained in:
+5
-2
@@ -100,6 +100,7 @@ void bip6_debug_enable(void)
|
|||||||
|
|
||||||
/* unix socket */
|
/* unix socket */
|
||||||
static int BIP6_Socket = -1;
|
static int BIP6_Socket = -1;
|
||||||
|
static int BIP6_Socket_Scope_Id = 0;
|
||||||
/* local address - filled by init functions */
|
/* local address - filled by init functions */
|
||||||
static BACNET_IP6_ADDRESS BIP6_Addr;
|
static BACNET_IP6_ADDRESS BIP6_Addr;
|
||||||
static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr;
|
static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr;
|
||||||
@@ -140,6 +141,7 @@ void bip6_set_interface(char *ifname)
|
|||||||
ntohs(sin->sin6_addr.s6_addr16[7]));
|
ntohs(sin->sin6_addr.s6_addr16[7]));
|
||||||
debug_print_ipv6(ifname, (&sin->sin6_addr));
|
debug_print_ipv6(ifname, (&sin->sin6_addr));
|
||||||
found = true;
|
found = true;
|
||||||
|
BIP6_Socket_Scope_Id = if_nametoindex(ifname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ifa_tmp = ifa_tmp->ifa_next;
|
ifa_tmp = ifa_tmp->ifa_next;
|
||||||
@@ -274,6 +276,7 @@ int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len)
|
|||||||
bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]);
|
bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]);
|
||||||
bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]);
|
bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]);
|
||||||
bvlc_dest.sin6_port = htons(dest->port);
|
bvlc_dest.sin6_port = htons(dest->port);
|
||||||
|
bvlc_dest.sin6_scope_id = BIP6_Socket_Scope_Id;
|
||||||
debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr);
|
debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr);
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0,
|
return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0,
|
||||||
@@ -464,8 +467,8 @@ bool bip6_init(char *ifname)
|
|||||||
IP6_ADDRESS_MAX);
|
IP6_ADDRESS_MAX);
|
||||||
memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address,
|
memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address,
|
||||||
sizeof(struct in6_addr));
|
sizeof(struct in6_addr));
|
||||||
/* Let system choose the interface */
|
/* Let system not choose the interface */
|
||||||
join_request.ipv6mr_interface = 0;
|
join_request.ipv6mr_interface = BIP6_Socket_Scope_Id;
|
||||||
status = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
status = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
||||||
&join_request, sizeof(join_request));
|
&join_request, sizeof(join_request));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
|||||||
+5
-2
@@ -90,6 +90,7 @@ void bip6_debug_enable(void)
|
|||||||
|
|
||||||
/* unix socket */
|
/* unix socket */
|
||||||
static int BIP6_Socket = -1;
|
static int BIP6_Socket = -1;
|
||||||
|
static int BIP6_Socket_Scope_Id = 0;
|
||||||
/* local address - filled by init functions */
|
/* local address - filled by init functions */
|
||||||
static BACNET_IP6_ADDRESS BIP6_Addr;
|
static BACNET_IP6_ADDRESS BIP6_Addr;
|
||||||
static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr;
|
static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr;
|
||||||
@@ -130,6 +131,7 @@ void bip6_set_interface(char *ifname)
|
|||||||
ntohs(sin->sin6_addr.s6_addr16[7]));
|
ntohs(sin->sin6_addr.s6_addr16[7]));
|
||||||
debug_print_ipv6(ifname, (&sin->sin6_addr));
|
debug_print_ipv6(ifname, (&sin->sin6_addr));
|
||||||
found = true;
|
found = true;
|
||||||
|
BIP6_Socket_Scope_Id = if_nametoindex(ifname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ifa_tmp = ifa_tmp->ifa_next;
|
ifa_tmp = ifa_tmp->ifa_next;
|
||||||
@@ -264,6 +266,7 @@ int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len)
|
|||||||
bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]);
|
bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]);
|
||||||
bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]);
|
bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]);
|
||||||
bvlc_dest.sin6_port = htons(dest->port);
|
bvlc_dest.sin6_port = htons(dest->port);
|
||||||
|
bvlc_dest.sin6_scope_id = BIP6_Socket_Scope_Id;
|
||||||
debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr);
|
debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr);
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0,
|
return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0,
|
||||||
@@ -454,8 +457,8 @@ bool bip6_init(char *ifname)
|
|||||||
IP6_ADDRESS_MAX);
|
IP6_ADDRESS_MAX);
|
||||||
memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address,
|
memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address,
|
||||||
sizeof(struct in6_addr));
|
sizeof(struct in6_addr));
|
||||||
/* Let system choose the interface */
|
/* Let system not choose the interface */
|
||||||
join_request.ipv6mr_interface = 0;
|
join_request.ipv6mr_interface = BIP6_Socket_Scope_Id;
|
||||||
status = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
status = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
||||||
&join_request, sizeof(join_request));
|
&join_request, sizeof(join_request));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
|||||||
+5
-2
@@ -46,6 +46,7 @@
|
|||||||
|
|
||||||
/* Win32 Socket */
|
/* Win32 Socket */
|
||||||
static SOCKET BIP6_Socket = INVALID_SOCKET;
|
static SOCKET BIP6_Socket = INVALID_SOCKET;
|
||||||
|
static int BIP6_Socket_Scope_Id = 0;
|
||||||
/* local address - filled by init functions */
|
/* local address - filled by init functions */
|
||||||
static BACNET_IP6_ADDRESS BIP6_Addr;
|
static BACNET_IP6_ADDRESS BIP6_Addr;
|
||||||
static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr;
|
static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr;
|
||||||
@@ -207,8 +208,9 @@ void bip6_set_interface(char *ifname)
|
|||||||
IP6_ADDRESS_MAX);
|
IP6_ADDRESS_MAX);
|
||||||
memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address,
|
memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address,
|
||||||
sizeof(struct in6_addr));
|
sizeof(struct in6_addr));
|
||||||
/* Let system choose the interface */
|
/* Let system not choose the interface */
|
||||||
join_request.ipv6mr_interface = 0;
|
BIP6_Socket_Scope_Id = if_nametoindex(ifname);
|
||||||
|
join_request.ipv6mr_interface = BIP6_Socket_Scope_Id;
|
||||||
RetVal = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
RetVal = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
||||||
(char *)&join_request, sizeof(join_request));
|
(char *)&join_request, sizeof(join_request));
|
||||||
if (RetVal < 0) {
|
if (RetVal < 0) {
|
||||||
@@ -389,6 +391,7 @@ int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len)
|
|||||||
bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]);
|
bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]);
|
||||||
bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]);
|
bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]);
|
||||||
bvlc_dest.sin6_port = htons(dest->port);
|
bvlc_dest.sin6_port = htons(dest->port);
|
||||||
|
bvlc_dest.sin6_scope_id = BIP6_Socket_Scope_Id;
|
||||||
debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr);
|
debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr);
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0,
|
return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user