Skip to content

Commit

Permalink
Add bind-address-ipv4 to upnp
Browse files Browse the repository at this point in the history
Pass the bind-address-ipv4 to upnpDiscover to allow for upnp to only
use the interface specified. Prevents upnp packet leaks.
  • Loading branch information
LaserEyess committed Mar 7, 2019
1 parent 95dd630 commit 782cf31
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
3 changes: 2 additions & 1 deletion libtransmission/port-forwarding.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ static void natPulse(tr_shared* s, bool do_check)
s->session->public_peer_port = public_peer_port;
}

s->upnpStatus = tr_upnpPulse(s->upnp, private_peer_port, is_enabled, do_check);
s->upnpStatus =
tr_upnpPulse(s->upnp, private_peer_port, is_enabled, do_check, tr_address_to_string(&s->session->public_ipv4->addr));

newStatus = tr_sharedTraversalStatus(s);

Expand Down
10 changes: 1 addition & 9 deletions libtransmission/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode)
****
***/

struct tr_bindinfo
{
tr_socket_t socket;
tr_address addr;
struct event* ev;
};

static void close_bindinfo(struct tr_bindinfo* b)
{
if (b != NULL && b->socket != TR_BAD_SOCKET)
Expand Down Expand Up @@ -1920,8 +1913,6 @@ static void sessionCloseImplStart(tr_session* session)

session->isClosing = true;

free_incoming_peer_port(session);

if (session->isLPDEnabled)
{
tr_lpdUninit(session);
Expand All @@ -1938,6 +1929,7 @@ static void sessionCloseImplStart(tr_session* session)

tr_verifyClose(session);
tr_sharedClose(session);
free_incoming_peer_port(session);
tr_rpcClose(&session->rpcServer);

/* Close the torrents. Get the most active ones first so that
Expand Down
7 changes: 7 additions & 0 deletions libtransmission/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ struct tr_cache;
struct tr_fdInfo;
struct tr_device_info;

struct tr_bindinfo
{
int socket;
tr_address addr;
struct event* ev;
};

struct tr_turtle_info
{
/* TR_UP and TR_DOWN speed limits */
Expand Down
12 changes: 6 additions & 6 deletions libtransmission/upnp.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void tr_upnpClose(tr_upnp* handle)
*** Wrappers for miniupnpc functions
**/

static struct UPNPDev* tr_upnpDiscover(int msec)
static struct UPNPDev* tr_upnpDiscover(int msec, char const* bindaddr)
{
struct UPNPDev* ret;
bool have_err;
Expand All @@ -89,14 +89,14 @@ static struct UPNPDev* tr_upnpDiscover(int msec)
int err = UPNPDISCOVER_SUCCESS;

#if (MINIUPNPC_API_VERSION >= 14) /* adds ttl */
ret = upnpDiscover(msec, NULL, NULL, 0, 0, 2, &err);
ret = upnpDiscover(msec, bindaddr, NULL, 0, 0, 2, &err);
#else
ret = upnpDiscover(msec, NULL, NULL, 0, 0, &err);
ret = upnpDiscover(msec, bindaddr, NULL, 0, 0, &err);
#endif

have_err = err != UPNPDISCOVER_SUCCESS;
#else
ret = upnpDiscover(msec, NULL, NULL, 0);
ret = upnpDiscover(msec, bindaddr, NULL, 0);
have_err = ret == NULL;
#endif

Expand Down Expand Up @@ -182,15 +182,15 @@ enum
UPNP_IGD_INVALID = 3
};

int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck)
int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck, char const* bindaddr)
{
int ret;

if (isEnabled && handle->state == TR_UPNP_DISCOVER)
{
struct UPNPDev* devlist;

devlist = tr_upnpDiscover(2000);
devlist = tr_upnpDiscover(2000, bindaddr);

errno = 0;

Expand Down
2 changes: 1 addition & 1 deletion libtransmission/upnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ tr_upnp* tr_upnpInit(void);

void tr_upnpClose(tr_upnp*);

int tr_upnpPulse(tr_upnp*, int port, bool isEnabled, bool doPortCheck);
int tr_upnpPulse(tr_upnp*, int port, bool isEnabled, bool doPortCheck, char const*);

/* @} */

0 comments on commit 782cf31

Please sign in to comment.