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

Split out syslog port #480

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cmd/smee/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ func countFlags(fs *flag.FlagSet) (n int) {

func syslogFlags(c *config, fs *flag.FlagSet) {
fs.BoolVar(&c.syslog.enabled, "syslog-enabled", true, "[syslog] enable Syslog server(receiver)")
fs.StringVar(&c.syslog.bindAddr, "syslog-addr", detectPublicIPv4(":514"), "[syslog] local IP:Port to listen on for Syslog messages")
fs.StringVar(&c.syslog.bindAddr, "syslog-addr", detectPublicIPv4(), "[syslog] local IP to listen on for Syslog messages")
fs.IntVar(&c.syslog.bindPort, "syslog-port", 514, "[syslog] local port to listen on for Syslog messages")
}

func tftpFlags(c *config, fs *flag.FlagSet) {
fs.BoolVar(&c.tftp.enabled, "tftp-enabled", true, "[tftp] enable iPXE TFTP binary server)")
fs.StringVar(&c.tftp.bindAddr, "tftp-addr", detectPublicIPv4(""), "[tftp] local IP to listen on for iPXE TFTP binary requests")
fs.StringVar(&c.tftp.bindAddr, "tftp-addr", detectPublicIPv4(), "[tftp] local IP to listen on for iPXE TFTP binary requests")
fs.IntVar(&c.tftp.bindPort, "tftp-port", 69, "[tftp] local port to listen on for iPXE TFTP binary requests")
fs.DurationVar(&c.tftp.timeout, "tftp-timeout", time.Second*5, "[tftp] iPXE TFTP binary server requests timeout")
fs.StringVar(&c.tftp.ipxeScriptPatch, "ipxe-script-patch", "", "[tftp/http] iPXE script fragment to patch into served iPXE binaries served via TFTP or HTTP")
Expand All @@ -100,7 +101,7 @@ func ipxeHTTPBinaryFlags(c *config, fs *flag.FlagSet) {

func ipxeHTTPScriptFlags(c *config, fs *flag.FlagSet) {
fs.BoolVar(&c.ipxeHTTPScript.enabled, "http-ipxe-script-enabled", true, "[http] enable iPXE HTTP script server")
fs.StringVar(&c.ipxeHTTPScript.bindAddr, "http-addr", detectPublicIPv4(""), "[http] local IP to listen on for iPXE HTTP script requests")
fs.StringVar(&c.ipxeHTTPScript.bindAddr, "http-addr", detectPublicIPv4(), "[http] local IP to listen on for iPXE HTTP script requests")
fs.IntVar(&c.ipxeHTTPScript.bindPort, "http-port", 8080, "[http] local port to listen on for iPXE HTTP script requests")
fs.StringVar(&c.ipxeHTTPScript.extraKernelArgs, "extra-kernel-args", "", "[http] extra set of kernel args (k=v k=v) that are appended to the kernel cmdline iPXE script")
fs.StringVar(&c.ipxeHTTPScript.trustedProxies, "trusted-proxies", "", "[http] comma separated list of trusted proxies in CIDR notation")
Expand All @@ -117,16 +118,16 @@ func dhcpFlags(c *config, fs *flag.FlagSet) {
fs.StringVar(&c.dhcp.mode, "dhcp-mode", "reservation", "[dhcp] DHCP mode (reservation, proxy)")
fs.StringVar(&c.dhcp.bindAddr, "dhcp-addr", "0.0.0.0:67", "[dhcp] local IP:Port to listen on for DHCP requests")
fs.StringVar(&c.dhcp.bindInterface, "dhcp-iface", "", "[dhcp] interface to bind to for DHCP requests")
fs.StringVar(&c.dhcp.ipForPacket, "dhcp-ip-for-packet", detectPublicIPv4(""), "[dhcp] IP address to use in DHCP packets (opt 54, etc)")
fs.StringVar(&c.dhcp.syslogIP, "dhcp-syslog-ip", detectPublicIPv4(""), "[dhcp] Syslog server IP address to use in DHCP packets (opt 7)")
fs.StringVar(&c.dhcp.tftpIP, "dhcp-tftp-ip", detectPublicIPv4(""), "[dhcp] TFTP server IP address to use in DHCP packets (opt 66, etc)")
fs.StringVar(&c.dhcp.ipForPacket, "dhcp-ip-for-packet", detectPublicIPv4(), "[dhcp] IP address to use in DHCP packets (opt 54, etc)")
fs.StringVar(&c.dhcp.syslogIP, "dhcp-syslog-ip", detectPublicIPv4(), "[dhcp] Syslog server IP address to use in DHCP packets (opt 7)")
fs.StringVar(&c.dhcp.tftpIP, "dhcp-tftp-ip", detectPublicIPv4(), "[dhcp] TFTP server IP address to use in DHCP packets (opt 66, etc)")
fs.IntVar(&c.dhcp.tftpPort, "dhcp-tftp-port", 69, "[dhcp] TFTP server port to use in DHCP packets (opt 66, etc)")
fs.StringVar(&c.dhcp.httpIpxeBinaryURL.Scheme, "dhcp-http-ipxe-binary-scheme", "http", "[dhcp] HTTP iPXE binaries scheme to use in DHCP packets")
fs.StringVar(&c.dhcp.httpIpxeBinaryURL.Host, "dhcp-http-ipxe-binary-host", detectPublicIPv4(""), "[dhcp] HTTP iPXE binaries host or IP to use in DHCP packets")
fs.StringVar(&c.dhcp.httpIpxeBinaryURL.Host, "dhcp-http-ipxe-binary-host", detectPublicIPv4(), "[dhcp] HTTP iPXE binaries host or IP to use in DHCP packets")
fs.IntVar(&c.dhcp.httpIpxeBinaryURL.Port, "dhcp-http-ipxe-binary-port", 8080, "[dhcp] HTTP iPXE binaries port to use in DHCP packets")
fs.StringVar(&c.dhcp.httpIpxeBinaryURL.Path, "dhcp-http-ipxe-binary-path", "/ipxe/", "[dhcp] HTTP iPXE binaries path to use in DHCP packets")
fs.StringVar(&c.dhcp.httpIpxeScript.Scheme, "dhcp-http-ipxe-script-scheme", "http", "[dhcp] HTTP iPXE script scheme to use in DHCP packets")
fs.StringVar(&c.dhcp.httpIpxeScript.Host, "dhcp-http-ipxe-script-host", detectPublicIPv4(""), "[dhcp] HTTP iPXE script host or IP to use in DHCP packets")
fs.StringVar(&c.dhcp.httpIpxeScript.Host, "dhcp-http-ipxe-script-host", detectPublicIPv4(), "[dhcp] HTTP iPXE script host or IP to use in DHCP packets")
fs.IntVar(&c.dhcp.httpIpxeScript.Port, "dhcp-http-ipxe-script-port", 8080, "[dhcp] HTTP iPXE script port to use in DHCP packets")
fs.StringVar(&c.dhcp.httpIpxeScript.Path, "dhcp-http-ipxe-script-path", "/auto.ipxe", "[dhcp] HTTP iPXE script path to use in DHCP packets")
fs.BoolVar(&c.dhcp.httpIpxeScript.injectMacAddress, "dhcp-http-ipxe-script-prepend-mac", true, "[dhcp] prepend the hardware MAC address to iPXE script URL base, http://1.2.3.4/auto.ipxe -> http://1.2.3.4/40:15:ff:89:cc:0e/auto.ipxe")
Expand Down Expand Up @@ -169,13 +170,13 @@ func newCLI(cfg *config, fs *flag.FlagSet) *ffcli.Command {
}
}

func detectPublicIPv4(extra string) string {
func detectPublicIPv4() string {
ip, err := autoDetectPublicIPv4()
if err != nil {
return ""
}

return fmt.Sprintf("%v%v", ip.String(), extra)
return ip.String()
}

func autoDetectPublicIPv4() (net.IP, error) {
Expand Down
10 changes: 6 additions & 4 deletions cmd/smee/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func TestParser(t *testing.T) {
want := config{
syslog: syslogConfig{
enabled: true,
bindAddr: "192.168.2.4:514",
bindAddr: "192.168.2.4",
bindPort: 514,
},
tftp: tftp{
blockSize: 512,
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestParser(t *testing.T) {
fs := flag.NewFlagSet(name, flag.ContinueOnError)
args := []string{
"-log-level", "info",
"-syslog-addr", "192.168.2.4:514",
"-syslog-addr", "192.168.2.4",
"-tftp-addr", "192.168.2.4",
"-http-addr", "192.168.2.4",
"-dhcp-ip-for-packet", "192.168.2.4",
Expand Down Expand Up @@ -97,7 +98,7 @@ func TestParser(t *testing.T) {
}

func TestCustomUsageFunc(t *testing.T) {
defaultIP := detectPublicIPv4("")
defaultIP := detectPublicIPv4()
want := fmt.Sprintf(`Smee is the DHCP and Network boot service for use in the Tinkerbell stack.

USAGE
Expand Down Expand Up @@ -142,8 +143,9 @@ FLAGS
-trusted-proxies [http] comma separated list of trusted proxies in CIDR notation
-otel-endpoint [otel] OpenTelemetry collector endpoint
-otel-insecure [otel] OpenTelemetry collector insecure (default "true")
-syslog-addr [syslog] local IP:Port to listen on for Syslog messages (default "%[1]v:514")
-syslog-addr [syslog] local IP to listen on for Syslog messages (default "%[1]v")
-syslog-enabled [syslog] enable Syslog server(receiver) (default "true")
-syslog-port [syslog] local port to listen on for Syslog messages (default "514")
-ipxe-script-patch [tftp/http] iPXE script fragment to patch into served iPXE binaries served via TFTP or HTTP
-tftp-addr [tftp] local IP to listen on for iPXE TFTP binary requests (default "%[1]v")
-tftp-block-size [tftp] TFTP block size a value between 512 (the default block size for TFTP) and 65456 (the max size a UDP packet payload can be) (default "512")
Expand Down
6 changes: 4 additions & 2 deletions cmd/smee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
type syslogConfig struct {
enabled bool
bindAddr string
bindPort int
}

type tftp struct {
Expand Down Expand Up @@ -154,9 +155,10 @@
g, ctx := errgroup.WithContext(ctx)
// syslog
if cfg.syslog.enabled {
log.Info("starting syslog server", "bind_addr", cfg.syslog.bindAddr)
addr := fmt.Sprintf("%s:%d", cfg.syslog.bindAddr, cfg.syslog.bindPort)
log.Info("starting syslog server", "bind_addr", addr)

Check warning on line 159 in cmd/smee/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/smee/main.go#L158-L159

Added lines #L158 - L159 were not covered by tests
g.Go(func() error {
if err := syslog.StartReceiver(ctx, log, cfg.syslog.bindAddr, 1); err != nil {
if err := syslog.StartReceiver(ctx, log, addr, 1); err != nil {

Check warning on line 161 in cmd/smee/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/smee/main.go#L161

Added line #L161 was not covered by tests
log.Error(err, "syslog server failure")
return err
}
Expand Down
Loading