Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New plugin: loop #1989

Merged
merged 10 commits into from
Jul 20, 2018
Merged

New plugin: loop #1989

merged 10 commits into from
Jul 20, 2018

Conversation

miekg
Copy link
Member

@miekg miekg commented Jul 20, 2018

Add a plugin that detects loops. It does this by sending an unique query
to our selves. If we see the query more than twice we stop the process.
If there isn't a loop, the plugin disables it self and becomes a noop
plugin.

Signed-off-by: Miek Gieben miek@miek.nl

@corbot corbot bot requested a review from greenpau July 20, 2018 13:44
@corbot
Copy link

corbot bot commented Jul 20, 2018

Thank you for your contribution. I've just checked the OWNERS files to find a suitable reviewer. This search was successful and I've asked greenpau (via /OWNERS) for a review.

If you have questions or suggestions for this bot, please file an issue against the miekg/dreck repository.

The bot understands the commands that are listed here.

@miekg miekg requested a review from chrisohaver July 20, 2018 13:44
@miekg
Copy link
Member Author

miekg commented Jul 20, 2018

Added @chrisohaver as reviewer as well, as I've volunteered him in the owners file

@greenpau
Copy link
Collaborator

@miekg , this one is pretty cool! 👍

Copy link
Member

@chrisohaver chrisohaver left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@greenpau greenpau left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@codecov-io
Copy link

codecov-io commented Jul 20, 2018

Codecov Report

Merging #1989 into master will decrease coverage by 0.12%.
The diff coverage is 36.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1989      +/-   ##
==========================================
- Coverage   54.79%   54.67%   -0.13%     
==========================================
  Files         198      200       +2     
  Lines        9639     9723      +84     
==========================================
+ Hits         5282     5316      +34     
- Misses       3948     3994      +46     
- Partials      409      413       +4
Impacted Files Coverage Δ
plugin/pkg/log/plugin.go 25% <0%> (-2.28%) ⬇️
plugin/loop/loop.go 25% <25%> (ø)
plugin/loop/setup.go 47.82% <47.82%> (ø)
plugin/forward/connect.go 86.48% <0%> (+4.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 547f155...a5784d3. Read the comment docs.


if l.seen() > 2 {
// TODO(miek): add log.Fatal(f) and use here.
log.Errorf("Seen \"HINFO IN %s\" more than twice, loop detected", l.qname)
Copy link
Member

@chrisohaver chrisohaver Jul 20, 2018

Choose a reason for hiding this comment

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

Can we also log the IP address that the loop was detected in? i.e the ip that the request came in on...

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, I'm my local testing this will always be localhost because there is no remote server at play.

@chrisohaver
Copy link
Member

looks great. Thanks Miek for whipping this one out lightning fast!

miekg added 5 commits July 20, 2018 14:08
Add a plugin that detects loops. It does this by sending an unique query
to our selves. If we see the query more than twice we stop the process.
If there isn't a loop, the plugin disables it self and becomes a noop
plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>
Signed-off-by: Miek Gieben <miek@miek.nl>
Signed-off-by: Miek Gieben <miek@miek.nl>
Signed-off-by: Miek Gieben <miek@miek.nl>
Signed-off-by: Miek Gieben <miek@miek.nl>
@chrisohaver
Copy link
Member

Added, I'm my local testing this will always be localhost because there is no remote server at play.

Ah - I meant to log the IP address that coredns received the packet on (i.e. the destination ip of the incoming packet).
In the Ubuntu resolved case, this would be 127.0.0.53, which may make it easier to understand (since that IP is in resolv.conf).

Signed-off-by: Miek Gieben <miek@miek.nl>
Signed-off-by: Miek Gieben <miek@miek.nl>
Copy link
Contributor

@fturib fturib left a comment

Choose a reason for hiding this comment

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

I think there may be some issues if bloc has several keys, or if config has several hosts.
Please see my comments.

}

if l.seen() > 2 {
// TODO(miek): add log.Fatal(f) and use here.
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand we create only one Loop struct. and we send several queries (every 2 sec).
so, this l.seen > 2 will be true at the third msg we send .. no ?

Should we have here a count for each msg.id we create for the test ?

}

if ok == len(conf.ListenHosts) {
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like a way to disable sooner if at least one msg sent per Listening host.
Because of the double loop (30 sec, and for each Host) - and because of 'continue" at line 46, we are not sure that all Host are tested. (some may be tested several time, some not at all).

c.OnStartup(func() error {
// Another Go function, otherwise we block startup and can't send the packet.
go func() {
deadline := time.Now().Add(30 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess 30 sec could be adapted to >= 2 * Nb of Listening Host.
I agree 15 seems already a big number ...


zone := "."
if len(c.ServerBlockKeys) > 0 {
zone = plugin.Host(c.ServerBlockKeys[0]).Normalize()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that setup is called for each of the serverBlocKeys.
There is a way to know which one we are called for : use c.Key

Signed-off-by: Miek Gieben <miek@miek.nl>
@miekg
Copy link
Member Author

miekg commented Jul 20, 2018 via email

@fturib
Copy link
Contributor

fturib commented Jul 20, 2018

I'll add the standard code that this can only be used once.

It is not about having several time the "loop" plugin in the same stanza.
It is about having several keys on top of the stanza, like:

coredns.io:53, coredns.com:443, infobloxcom:667 {
    loop
    procxy ...
}

the setup of loop will be triggered 3 times : one for each key on the top.
and from the setup(...) function you get that key with : c.Key

@miekg
Copy link
Member Author

miekg commented Jul 20, 2018 via email

@miekg
Copy link
Member Author

miekg commented Jul 20, 2018

coredns.io:1053 coredns.com:1054 infoblox.com:1055 {
    loop
    forward . 127.0.0.1:1054
    log
}

crashes with:

127.0.0.1:47153 - [20/Jul/2018:18:57:23 +0100] 738 "HINFO IN 1687376426597664323.1119963552489870178.coredns.io. udp 68 false 512" REFUSED qr,rd 68 0.000187187s
127.0.0.1:34498 - [20/Jul/2018:18:57:23 +0100] 45646 "HINFO IN 1687376426597664323.1119963552489870178.coredns.io. udp 68 false 512" REFUSED qr,rd 68 0.000087221s
2018/07/20 18:57:23 [FATAL] plugin/loop: Seen "HINFO IN 1687376426597664323.1119963552489870178.coredns.io." to [::]:1053 more than twice, loop detected

miekg added 2 commits July 20, 2018 19:13
Signed-off-by: Miek Gieben <miek@miek.nl>
Signed-off-by: Miek Gieben <miek@miek.nl>
@miekg miekg merged commit 84ec780 into master Jul 20, 2018
@corbot corbot bot deleted the loop branch July 20, 2018 18:45
@luxas
Copy link

luxas commented Jul 23, 2018

@rajansandeep @miekg @johnbelamaric Will this option make it into the next k8s manifest that has a new enough CoreDNS version?

@miekg
Copy link
Member Author

miekg commented Jul 23, 2018 via email

@chrisohaver
Copy link
Member

Will this option make it into the next k8s manifest that has a new enough CoreDNS version?

Yes

@chrisohaver
Copy link
Member

What's the timeframe?

Plenty of time to get it into the next k8s release.

@fturib
Copy link
Contributor

fturib commented Jul 23, 2018

In that case it would not be considered as a feature.
rather update of existing feature. Code slush is Aug 28th.
We would need to have CoreDNS 1.2.1 released by Aug20th.

@chrisohaver
Copy link
Member

chrisohaver commented Jul 23, 2018

Yes, thanks. I relayed the wrong freeze ... FYI...

https://github.com/kubernetes/sig-release/blob/master/releases/release-1.12/release-1.12.md

mdgreenfield pushed a commit to DataDog/coredns that referenced this pull request Mar 4, 2019
* New plugin: loop

Add a plugin that detects loops. It does this by sending an unique query
to our selves. If we see the query more than twice we stop the process.
If there isn't a loop, the plugin disables it self and becomes a noop
plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>
Jason-ZW pushed a commit to rancher/coredns that referenced this pull request Apr 17, 2019
* New plugin: loop

Add a plugin that detects loops. It does this by sending an unique query
to our selves. If we see the query more than twice we stop the process.
If there isn't a loop, the plugin disables it self and becomes a noop
plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>
dna2github pushed a commit to dna2fork/coredns that referenced this pull request Jul 19, 2019
* New plugin: loop

Add a plugin that detects loops. It does this by sending an unique query
to our selves. If we see the query more than twice we stop the process.
If there isn't a loop, the plugin disables it self and becomes a noop
plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants