diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-06-28 11:07:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-06-28 11:07:52 +0000 |
commit | 34c384edf42db39955b54a640dc37e7067217229 (patch) | |
tree | 8f9bd2ced347738489f42de665bd55dbb998808d /src/transport/plugin_transport_udp.c | |
parent | 618779d80c15219b8d9504067f286b5ac1b9b194 (diff) | |
download | gnunet-34c384edf42db39955b54a640dc37e7067217229.tar.gz gnunet-34c384edf42db39955b54a640dc37e7067217229.zip |
fixes to plugin API for DV
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 52e598189..724dfe6b3 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1586,47 +1586,77 @@ udp_transport_server_start (void *cls) | |||
1586 | } | 1586 | } |
1587 | 1587 | ||
1588 | 1588 | ||
1589 | |||
1590 | /** | ||
1591 | * Check if the given port is plausible (must be either | ||
1592 | * our listen port or our advertised port). If it is | ||
1593 | * neither, we return GNUNET_SYSERR. | ||
1594 | * | ||
1595 | * @param plugin global variables | ||
1596 | * @param in_port port number to check | ||
1597 | * @return GNUNET_OK if port is either open_port or adv_port | ||
1598 | */ | ||
1599 | static int | ||
1600 | check_port (struct Plugin *plugin, uint16_t in_port) | ||
1601 | { | ||
1602 | if (in_port == plugin->port) | ||
1603 | return GNUNET_OK; | ||
1604 | return GNUNET_SYSERR; | ||
1605 | } | ||
1606 | |||
1607 | |||
1589 | /** | 1608 | /** |
1590 | * Another peer has suggested an address for this peer and transport | 1609 | * Function that will be called to check if a binary address for this |
1591 | * plugin. Check that this could be a valid address. This function | 1610 | * plugin is well-formed and corresponds to an address for THIS peer |
1592 | * is not expected to 'validate' the address in the sense of trying to | 1611 | * (as per our configuration). Naturally, if absolutely necessary, |
1593 | * connect to it but simply to see if the binary format is technically | 1612 | * plugins can be a bit conservative in their answer, but in general |
1594 | * legal for establishing a connection. | 1613 | * plugins should make sure that the address does not redirect |
1614 | * traffic to a 3rd party that might try to man-in-the-middle our | ||
1615 | * traffic. | ||
1595 | * | 1616 | * |
1596 | * @param cls closure, should be our handle to the Plugin | 1617 | * @param cls closure, should be our handle to the Plugin |
1597 | * @param addr pointer to the address, may be modified (slightly) | 1618 | * @param addr pointer to the address |
1598 | * @param addrlen length of addr | 1619 | * @param addrlen length of addr |
1599 | * @return GNUNET_OK if this is a plausible address for this peer | 1620 | * @return GNUNET_OK if this is a plausible address for this peer |
1600 | * and transport, GNUNET_SYSERR if not | 1621 | * and transport, GNUNET_SYSERR if not |
1601 | * | 1622 | * |
1602 | */ | 1623 | */ |
1603 | static int | 1624 | static int |
1604 | udp_check_address (void *cls, void *addr, size_t addrlen) | 1625 | udp_check_address (void *cls, |
1626 | const void *addr, | ||
1627 | size_t addrlen) | ||
1605 | { | 1628 | { |
1606 | struct Plugin *plugin = cls; | 1629 | struct Plugin *plugin = cls; |
1607 | char buf[sizeof (struct sockaddr_in6)]; | 1630 | struct IPv4UdpAddress *v4; |
1631 | struct IPv6UdpAddress *v6; | ||
1608 | 1632 | ||
1609 | struct sockaddr_in *v4; | 1633 | if ((addrlen != sizeof (struct IPv4UdpAddress)) && |
1610 | struct sockaddr_in6 *v6; | 1634 | (addrlen != sizeof (struct IPv6UdpAddress))) |
1611 | |||
1612 | if ((addrlen != sizeof (struct sockaddr_in)) && | ||
1613 | (addrlen != sizeof (struct sockaddr_in6))) | ||
1614 | { | 1635 | { |
1615 | GNUNET_break_op (0); | 1636 | GNUNET_break_op (0); |
1616 | return GNUNET_SYSERR; | 1637 | return GNUNET_SYSERR; |
1617 | } | 1638 | } |
1618 | memcpy (buf, addr, sizeof (struct sockaddr_in6)); | 1639 | if (addrlen == sizeof (struct IPv4UdpAddress)) |
1619 | if (addrlen == sizeof (struct sockaddr_in)) | ||
1620 | { | 1640 | { |
1621 | v4 = (struct sockaddr_in *) buf; | 1641 | v4 = (struct IPv4UdpAddress *) addr; |
1622 | v4->sin_port = htons (plugin->port); | 1642 | if (GNUNET_OK != |
1643 | check_port (plugin, ntohs (v4->u_port))) | ||
1644 | return GNUNET_SYSERR; | ||
1645 | /* FIXME: check IP! */ | ||
1623 | } | 1646 | } |
1624 | else | 1647 | else |
1625 | { | 1648 | { |
1626 | v6 = (struct sockaddr_in6 *) buf; | 1649 | v6 = (struct IPv6UdpAddress *) addr; |
1627 | v6->sin6_port = htons (plugin->port); | 1650 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) |
1651 | { | ||
1652 | GNUNET_break_op (0); | ||
1653 | return GNUNET_SYSERR; | ||
1654 | } | ||
1655 | if (GNUNET_OK != | ||
1656 | check_port (plugin, ntohs (v6->u6_port))) | ||
1657 | return GNUNET_SYSERR; | ||
1658 | /* FIXME: check IP! */ | ||
1628 | } | 1659 | } |
1629 | |||
1630 | #if DEBUG_UDP | 1660 | #if DEBUG_UDP |
1631 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1661 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1632 | "udp", | 1662 | "udp", |