Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Implement RFC 7871 EDNS Client Subnet (ECS) #88

Merged
merged 1 commit into from May 28, 2020

Conversation

rfinnie
Copy link
Contributor

@rfinnie rfinnie commented May 10, 2020

In a nutshell, ECS is like X-Forwarded-For for DNS, and lets DNS
resolvers and proxies tell authoritative servers where the request
originated (down to a /24 v4 or /56 v6 network). IMHO this should
be the default, but I've left it as an option.

Copy link
Contributor

@chantra chantra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This would actually address #27 to some extend.

I think there is a couple of edge-cases to handle, but otherwise, this LGTM.

test/test_utils.py Show resolved Hide resolved
dohproxy/utils.py Outdated Show resolved Hide resolved
@rfinnie
Copy link
Contributor Author

rfinnie commented May 22, 2020

Sorry for the delay, I got nerd sniped into another larger project after getting most of this done.

Updated and rebased! Please re-review.

@chantra
Copy link
Contributor

chantra commented May 22, 2020

Thanks @rfinnie !
I am entering a long weekend so it may take a few days before I get a chance to look at it. Probably will check this early next week.

@rfinnie rfinnie force-pushed the ecs branch 4 times, most recently from 7fea025 to 1cadad4 Compare May 27, 2020 01:51
Copy link
Contributor

@chantra chantra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @rfinnie .

I got a couple of comments as to how to handle the addition/removal of the ECS option, but otherwise, lgtm.

Comment on lines 67 to 68
if original_ecs_option is not None:
options.append(original_ecs_option)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be invalid as it would put an ECS query option in the response.
I think the logic would be something along:

if original_ecs_option is None:
  pop_ecs_from_response()

e.g, if we were not provided an ECS optiopn in the query, we would take it out of the response, otherwise we leave it untouched.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. That logic was from earlier on when trying to deal with a scenario where the client had ECS set but we were modifying ECS anyway, which of course we don't actually want to do. I was able to simplify the logic now and not need to track the original ECS option, just by passing from set_dns_ecs() whether our ECS was actually set or not. The logic should be sound now.

Comment on lines 71 to 72
dnsr.edns = dnsq.edns
dnsr.options = options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, we only need to "reset" EDNS if we modified it in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it's now part of "if dnsr is not None and we_set_ecs".

dohproxy/server_protocol.py Show resolved Hide resolved
In a nutshell, ECS is like X-Forwarded-For for DNS, and lets DNS
resolvers and proxies tell authoritative servers where the request
originated (down to a /24 v4 or /56 v6 network).

This implementation preserves existing (and hence should be more
specific) ECS options.
Copy link
Contributor

@chantra chantra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rfinnie . Let's ship this!

@chantra chantra merged commit 289b9a5 into facebookarchive:master May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants