aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_config.c
AgeCommit message (Collapse)Author
2021-03-12Run "make autostyle" in advance of new series.Nick Mathewson
2021-03-12Update copyrights to 2021, using "make update-copyright"Nick Mathewson
2021-02-24Merge branch 'maint-0.4.5'David Goulet
2021-02-23relay: Avoid a directory early fetchDavid Goulet
The directory_fetches_from_authorities() is used to know if a client or relay should fetch data from an authority early in the boot process. We had a condition in that function that made a relay trigger that fetch if it didn't know its address (so we can learn it). However, when this is called, the address discovery has not been done yet so it would always return true for a relay. Furthermore, it would always trigger a log notice that the IPv4 couldn't be found which was inevitable because the address discovery process has not been done yet (done when building our first descriptor). It is also important to point out that starting in 0.4.5.1-alpha, asking an authority for an address is done during address discovery time using a one-hop circuit thus independent from the relay deciding to fetch or not documents from an authority. Small fix also is to reverse the "IPv(4|6)Only" flag in the notice so that if we can't find IPv6 it would output to use IPv4Only. Fixes #40300 Signed-off-by: David Goulet <dgoulet@torproject.org>
2021-02-19hs-v2: Removal of service and relay supportDavid Goulet
This is unfortunately massive but both functionalities were extremely intertwined and it would have required us to actually change the HSv2 code in order to be able to split this into multiple commits. After this commit, there are still artefacts of v2 in the code but there is no more support for service, intro point and HSDir. The v2 support for rendezvous circuit is still available since that code is the same for the v3 and we will leave it in so if a client is able to rendezvous on v2 then it can still transfer traffic. Once the entire network has moved away from v2, we can remove v2 rendezvous point support. Related to #40266 Signed-off-by: David Goulet <dgoulet@torproject.org>
2021-02-19hs-v2: Remove client supportDavid Goulet
Related to #40266 Signed-off-by: David Goulet <dgoulet@torproject.org>
2021-02-12Merge branch 'tor-gitlab/mr/304' into maint-0.4.5David Goulet
2021-02-12test: Fix duplicate ORPort testDavid Goulet
The comment of that specific unit test wanted 4 ORPorts but for some reasons we tested for 3 which before the previous commit related to #40289, test would pass but it was in fact wrong. Now the code is correct and 4 was in fact correct expected number of ports. Related to #40289 Signed-off-by: David Goulet <dgoulet@torproject.org>
2021-02-10relay: Allow RFC1918 addresses for non public relaysDavid Goulet
In other words, if PublishServerDescriptor is set to 0 and AssumeReachable to 1, then allow a relay to hold a RFC1918 address. Reasons for this are documented in #40208 Fixes #40208 Signed-off-by: David Goulet <dgoulet@torproject.org>
2021-01-19relay: Keep all ORPorts that are on different portsDavid Goulet
We used to actually discard ORPorts that were the same port and same family but they could have different address. Instead, we need to keep all different ORPorts so we can bind a listener on each of them. We will publish only one of these in our descriptor though. Related to #40246 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-19Merge branch 'maint-0.4.4' into maint-0.4.5Alexander Færøy
2020-11-19Merge branch 'maint-0.4.3' into maint-0.4.4Alexander Færøy
2020-11-13port: Don't ignore ports of a different familyDavid Goulet
Commit c3a0f757964de0e8a24911d72abff5df20bb323c added this feature for ORPort that we ignore any port that is not the family of our default address when parsing the port. So if port_parse_config() was called with an IPv4 default address, all IPv6 address would be ignored. That makes sense for ORPort since we call twice port_parse_config() for 0.0.0.0 and [::] but for the rest of the ports, it is not good since a perfectly valid configuration can be: SocksPort 9050 SocksPort [::1]:9050 Any non-ORPort only binds by default to an IPv4 except the ORPort that binds to both IPv4 and IPv6 by default. The fix here is to always parse all ports within port_parse_config() and then, specifically for ORPort, remove the duplicates or superseding ones. The warning is only emitted when a port supersedes another. A unit tests is added to make sure SocksPort of different family always exists together. Fixes #40183 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-12Fix typos.Samanta Navarro
Typos found with codespell. Please keep in mind that this should have impact on actual code and must be carefully evaluated: src/core/or/lttng_circuit.inc - ctf_enum_value("CONTROLER", CIRCUIT_PURPOSE_CONTROLLER) + ctf_enum_value("CONTROLLER", CIRCUIT_PURPOSE_CONTROLLER)
2020-11-05Make config/parse_tcp_proxy_line work in the presence of DNS hijackingNick Mathewson
We can use our existing mocking functionality to do this: We have been in this position before. Fixes part of #40179; bugfix on 0.4.3.1-alpha.
2020-08-12Merge remote-tracking branch 'tor-gitlab/mr/62'Nick Mathewson
2020-07-30Write unittest for #40065.George Kadianakis
Make the unit test pass by including an explicit IPv6 port and an implicit IPv4 port. See comments for more details.
2020-07-24relay: Turn find address "method_used" into enumDavid Goulet
Enum allows us to easily compare what is being returned but also better semantic to the code. Related #33247 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21relay: Automatically Enable an IPv6 ORPortDavid Goulet
This commit makes it that if the ORPort is set with a single port, it will bind to both global listen IPv4 and IPv6 addresses. To pin an "ORPort <PORT>" to be IPv4 or IPv6, the IPv4Only/IPv6Only flags are honored thus this will _only_ bind on IPv6 for that port value: ORPort 9050 IPv6Only Results in: [::]:9050 ORPort 9051 IPv4Only Results in: [0.0.0.0]:9051 Attempting to configure an explicit IPv4 address with IPv6Only flag is an error and vice versa. Closes #33246 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21Rename get_first_advertised_{addr,port}_by_type_af().Nick Mathewson
Rationale: these don't actually give the first advertised address/port, but instead give us the first such port that we are _configured_ to advertise. Putting them in a portconf_ namespace therefore makes sense. Similarly, there are no other functions that get the first configured advertised addr/port, so the "by_type_af()" part is needless. This is an automated commit, generated by this command: ./scripts/maint/rename_c_identifier.py \ get_first_advertised_addr_by_type_af portconf_get_first_advertised_addr \ get_first_advertised_port_by_type_af portconf_get_first_advertised_port
2020-07-21relay: Add AddressDisableIPv6 torrc optionDavid Goulet
This option controls if a tor relay will attempt address auto discovery and thus ultimately publish an IPv6 ORPort in the descriptor. Behavior is from proposal 312 section 3.2.6. Closes #33245 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20relay: Use flags in relay_find_addr_to_publish()David Goulet
Instead of a boolean saying "cache_only" add the concept of flags so we add semantic through out the code and allow ourselves to have more options in the future. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20test: Move unit tests to new find address interfaceDavid Goulet
Remove use of router_pick_published_address() and use relay_find_addr_to_publish instead. Related to #40025 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20addr: Continue discovery if Address exits but not for wanted familyDavid Goulet
Commit b14b1f2b1d9 was a mistake. In case an Address statement is missing for the wanted family but another one exists for another family, simply continue the address discovery. It is not a mistake to be missing an Address statement for a family because the address could simply be discovered by the next methods. Not all address family requires a specific Address statement. However, we do bail if we couldn't find any valid address for the requested family _and_ a resolve failed meaning we had a hostname but couldn't resolve it. In that case, we can't know if that hostname would have been for v4 or v6 thus we can't continue the address discovery properly. Couple unit tests case were removed to match this reality. Related #40025 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-15Fix small memory leak in config include testsDaniel Pinto
Tests that used options_init_from_string were not freeing calling config_free_all().
2020-07-15Add support for patterns on %include #25140Daniel Pinto
Also adds generic tor_glob function to expand globs.
2020-07-14addr: Use tor_addr_t instead of uint32_t for IPv4David Goulet
This changes a LOT of code but in the end, behavior is the same. Unfortunately, many functions had to be changed to accomodate but in majority of cases, to become simpler. Functions are also removed specifically those that were there to convert an IPv4 as a host format to a tor_addr_t. Those are not needed anymore. The IPv4 address field has been standardized to "ipv4_addr", the ORPort to "ipv4_orport" (currently IPv6 uses ipv6_orport) and DirPort to "ipv4_dirport". This is related to Sponsor 55 work that adds IPv6 support for relays and this work is needed in order to have a common interface between IPv4 and IPv6. Closes #40043. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-09Merge branch 'maint-0.4.4'Nick Mathewson
2020-07-07Revert "config: Make clients tell dual-stack exits they prefer IPv6"David Goulet
This reverts commit bf2a399fc0d90df76e091fa3259f7c1b8fb87781. Don't set by default the prefer IPv6 feature on client ports because it breaks the torsocks use case. The SOCKS resolve command is lacking a mechanism to ask for a specific address family (v4 or v6) thus prioritizing IPv6 when an IPv4 address is asked on the resolve SOCKS interface resulting in a failure. Tor Browser explicitly set PreferIPv6 so this should not affect the majority of our users. Closes #33796 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-07addr: Attempt to learn our address with ORPortDavid Goulet
If no Address statement are found in the configuration file, attempt to learn our address by looking at the ORPort address if any. Specifying an address is optional so if we can't find one, it is fine, we move on to the next discovery mechanism. Note that specifying a hostname on the ORPort is not yet supported at this commit. Closes #33236 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-06Fix coccinelle complaint in test_config.cNick Mathewson
2020-07-06addr: Fix possible memleak in find_my_address()David Goulet
Unit tests also suffered from a memleak. Closes #40024 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-02addr: Prioritize interface lookup over local hostnameDavid Goulet
The find_my_address() function now prioritize the local interface over the local hostname when guessing the IP address. See proposal 312, section 3.2.1, general case: https://gitweb.torproject.org/torspec.git/tree/proposals/312-relay-auto-ipv6-addr.txt#n359 The entire unit tests had to be refactored to make this possible. Instead of hot patching it, it has been rewritten to cover all possible cases and the test interface has been changed to accomodate both IPv4 and IPv6 in order for them to be tested identically. Closes #33238 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-30test: Mixed unit tests for find_my_address()David Goulet
This unit tests validates the use of IPv4 _and_ IPv6 together as in multiple option Address lines both addresses and hostnames. Closes #33235 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-30test: Unit tests for find_my_address() IPv6David Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-30test: Rename function to be IPv4 specificDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-29Merge remote-tracking branch 'tor-github/pr/1829/head' into maint-0.4.3Nick Mathewson
2020-06-24test: Modernize find_my_address() unit testDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Remove resolve_my_address_v4()David Goulet
Replace it by find_my_address() everywhere. This changes many parts of the code that uses it to use a tor_addr_t instead of a plain uint32_t for IPv4. Many changes to the unit test to also use the new interface. Part #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Make resolve_my_address_v4() use find_my_address()David Goulet
In order to transition smoothly, maek resolve_my_address_v4() call the new fancy find_my_address() with AF_INET. Next commits should remove the use of resolve_my_address_v4() accross the code to use find_my_address(). This commit is so the unit tests would be more easily fixed and port to the new find_my_address() internals. Part of #33233. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-23addr: Rename resolve_my_address to be v4 specificDavid Goulet
Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-23config: Change Address to be a LINELISTDavid Goulet
With prop312, we want to support IPv4 and IPv6 thus multiple Address statement (up to 2) will be accepted. For this, "Address" option becomes a LINELIST so we can properly process the IPv4 or/and IPv6. Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-05-05relay: Rename relay_resolve_addr.{c|h} fileDavid Goulet
New name is more accurate semantically. Closes #33789 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-05-05config: New file resolve_addr.{c|h}David Goulet
Move a series of function from config.c into that new file which is related to address resolving. Part of #33789 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-05-05relay: New file relay_resolve_addr.{c|h}David Goulet
This commit moves router_pick_published_address() and the related helper functions into the new file. The log_addr_has_changed() function has been made public in router.h so we can use it in relay_resolve_addr.c. This is a refactoring as part of Sponsor 55. Only code movement at this commit. Part of #33789 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-04-09client: Revert setting PreferIPv6 on by defaultDavid Goulet
This change broke torsocks that by default is expecting an IPv4 for hostname resolution because it can't ask tor for a specific IP version with the SOCKS5 extension. PreferIPv6 made it that sometimes the IPv6 could be returned to torsocks that was expecting an IPv4. Torsocks is probably a very unique case because the runtime flow is that it hijacks DNS resolution (ex: getaddrinfo()), gets an IP and then sends it back for the connect() to happen. The libc has DNS resolution functions that allows the caller to request a specific INET family but torsocks can't tell tor to resolve the hostname only to an IPv4 or IPv6 and thus by default fallsback to IPv4. Reverting this change into 0.4.3.x series but we'll keep it in the 0.4.4.x series in the hope that we add this SOCKS5 extension to tor for DNS resolution and then change torsocks to use that. Fixes #33804 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-03-21Merge branch 'bug32588_042' into bug32588_043teor
Merge static function declaration deletions from bug32588_042 and maint-0.4.3 in app/config/config.c.
2020-03-21Merge branch 'bug32588_041' into bug32588_042teor
2020-03-21Merge branch 'bug32588_035' into bug32588_041teor
Merge tests from maint-0.4.1 with new tests from bug32588_035 in test_router.c.
2020-03-21Add tests for get_first_advertised_{addr,port}_by_type_af()Nick Mathewson