#116 Add domain search list plugin

Open Rory wkronmiller

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 5 files from the diff.

@@ -0,0 +1,77 @@
Loading
1 +
// Copyright 2018-present the CoreDHCP Authors. All rights reserved
2 +
// This source code is licensed under the MIT license found in the
3 +
// LICENSE file in the root directory of this source tree.
4 +
5 +
package searchdomains
6 +
7 +
// This is an searchdomains plugin that adds default DNS search domains.
8 +
9 +
import (
10 +
	"github.com/coredhcp/coredhcp/handler"
11 +
	"github.com/coredhcp/coredhcp/logger"
12 +
	"github.com/coredhcp/coredhcp/plugins"
13 +
	"github.com/insomniacslk/dhcp/dhcpv4"
14 +
	"github.com/insomniacslk/dhcp/dhcpv6"
15 +
	"github.com/insomniacslk/dhcp/rfc1035label"
16 +
)
17 +
18 +
var log = logger.GetLogger("plugins/searchdomains")
19 +
20 +
// Plugin wraps the default DNS search domain options.
21 +
// Note that importing the plugin is not enough to use it: you have to
22 +
// explicitly specify the intention to use it in the `config.yml` file, in the
23 +
// plugins section. For searchdomains:
24 +
//
25 +
// server6:
26 +
//   listen: '[::]547'
27 +
//   - searchdomains: domain.a domain.b
28 +
//   - server_id: LL aa:bb:cc:dd:ee:ff
29 +
//   - file: "leases.txt"
30 +
//
31 +
var Plugin = plugins.Plugin{
32 +
	Name:   "searchdomains",
33 +
	Setup6: setup6,
34 +
	Setup4: setup4,
35 +
}
36 +
37 +
// These are the DNS search domains that are set by the plugin.
38 +
// Note that DHCPv4 and DHCPv6 options are totally independent.
39 +
// If you need the same settings for both, you'll need to configure
40 +
// this plugin once for the v4 and once for the v6 server.
41 +
var v4SearchList []string
42 +
var v6SearchList []string
43 +
44 +
// copySlice creates a new copy of a string slice in memory.
45 +
// This helps to ensure that downstream plugins can't corrupt
46 +
// this plugin's configuration
47 +
func copySlice(original []string) []string {
48 +
	copied := make([]string, len(original))
49 +
	copy(copied, original)
50 +
	return copied
51 +
}
52 +
53 +
func setup6(args ...string) (handler.Handler6, error) {
54 +
	v6SearchList = args
55 +
	log.Printf("Registered domain search list (DHCPv6) %s", v6SearchList)
56 +
	return domainSearchListHandler6, nil
57 +
}
58 +
59 +
func setup4(args ...string) (handler.Handler4, error) {
60 +
	v4SearchList = args
61 +
	log.Printf("Registered domain search list (DHCPv4) %s", v4SearchList)
62 +
	return domainSearchListHandler4, nil
63 +
}
64 +
65 +
func domainSearchListHandler6(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
66 +
	resp.UpdateOption(dhcpv6.OptDomainSearchList(&rfc1035label.Labels{
67 +
		Labels: copySlice(v6SearchList),
68 +
	}))
69 +
	return resp, false
70 +
}
71 +
72 +
func domainSearchListHandler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
73 +
	resp.UpdateOption(dhcpv4.OptDomainSearch(&rfc1035label.Labels{
74 +
		Labels: copySlice(v4SearchList),
75 +
	}))
76 +
	return resp, false
77 +
}

Learn more Showing 9 files with coverage changes found.

Changes in plugins/prefix/plugin.go
-9
-2
-1
Loading file...
Changes in plugins/allocators/bitmap/bitmap.go
-5
Loading file...
Changes in plugins/dns/plugin.go
-2
-4
Loading file...
Changes in plugins/allocators/ipcalc.go
-2
Loading file...
Changes in plugins/serverid/plugin.go
-1
-3
Loading file...
Changes in config/config.go
-1
-15
Loading file...
Changes in config/errors.go
-3
Loading file...
Changes in plugins/allocators/allocator.go
-1
Loading file...
New file plugins/searchdomains/plugin.go
New
Loading file...
Files Coverage
config +<.01% 5.29%
plugins +1.33% 48.04%
Project Totals (9 files) 32.77%
Loading