Skip to content

Commit

Permalink
EvseV2G: SDP bind only on one interface (#615)
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Claussen <[email protected]>
  • Loading branch information
corneliusclaussen authored Apr 2, 2024
1 parent 2539f6d commit c284515
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions modules/EvseV2G/sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ int sdp_init(struct v2g_context* v2g_ctx) {
return -1;
}

if (v2g_ctx->local_tcp_addr) {
memcpy(&sdp_addr.sin6_addr, &v2g_ctx->local_tcp_addr->sin6_addr, sizeof(sdp_addr.sin6_addr));
} else if (v2g_ctx->local_tls_addr) {
memcpy(&sdp_addr.sin6_addr, &v2g_ctx->local_tls_addr->sin6_addr, sizeof(sdp_addr.sin6_addr));
} else {
dlog(DLOG_LEVEL_ERROR, "Neither TLS nor TCP server on %s", v2g_ctx->if_name);
return -1;
}

/* create receiving socket */
v2g_ctx->sdp_socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (v2g_ctx->sdp_socket == -1) {
Expand All @@ -252,6 +243,16 @@ int sdp_init(struct v2g_context* v2g_ctx) {

dlog(DLOG_LEVEL_INFO, "SDP socket setup succeeded");

/* bind only to specified device */
if (setsockopt(v2g_ctx->sdp_socket, SOL_SOCKET, SO_BINDTODEVICE, v2g_ctx->if_name, strlen(v2g_ctx->if_name)) ==
-1) {
dlog(DLOG_LEVEL_ERROR, "setsockopt(SO_BINDTODEVICE) failed: %s", strerror(errno));
close(v2g_ctx->sdp_socket);
return -1;
}

dlog(DLOG_LEVEL_TRACE, "bind only to specified device");

/* join multicast group */
if (setsockopt(v2g_ctx->sdp_socket, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1) {
dlog(DLOG_LEVEL_ERROR, "setsockopt(IPV6_JOIN_GROUP) failed: %s", strerror(errno));
Expand Down

0 comments on commit c284515

Please sign in to comment.