nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: metallb/metallb
Pull request #706 (2020-08-26 17:09:22)

Disallow duplicate peers in config
Configuring the same peer twice is an error. Configuring two identical peers results in a rapidly-flapping BGP session. This PR disallows identical peers in the configuration. In the future we may want to perform smarter checks, however at the very least this fix will catch copy-paste mistakes.

russellb: Thanks for including the test case!  This looks like a reasonable interim fix, at least.  As you suggest, we probably want to consider some smarter validation, but what you have is an improvement over what's there now, so +1 from me.

lgtm to merge
johananl: Thanks Russell. I'll wait for a quick approval by @rata or @daxmc99.

Patch:
diff --git a/internal/config/config.go b/internal/config/config.go
index f41c4266..866f8229 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -18,6 +18,7 @@ import (
 	"errors"
 	"fmt"
 	"net"
+	"reflect"
 	"strconv"
 	"strings"
 	"time"
@@ -200,6 +201,14 @@ func Parse(bs []byte) (*Config, error) {
 		if err != nil {
 			return nil, fmt.Errorf("parsing peer #%d: %s", i+1, err)
 		}
+		for _, ep := range cfg.Peers {
+			// TODO: Be smarter regarding conflicting peers. For example, two
+			// peers could have a different hold time but they'd still result
+			// in two BGP sessions between the speaker and the remote host.
+			if reflect.DeepEqual(peer, ep) {
+				return nil, fmt.Errorf("peer #%d already exists", i+1)
+			}
+		}
 		cfg.Peers = append(cfg.Peers, peer)
 	}
 


Test patch:
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 2ff39125..0a50d10b 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -345,6 +345,19 @@ peers:
 `,
 		},
 
+		{
+			desc: "duplicate peers",
+			raw: `
+peers:
+- my-asn: 42
+  peer-asn: 42
+  peer-address: 1.2.3.4
+- my-asn: 42
+  peer-asn: 42
+  peer-address: 1.2.3.4
+`,
+		},
+
 		{
 			desc: "no pool name",
 			raw: `
Repository: metallb/metallb
Pull request #708 (2020-09-02 12:20:58)

website: Rephrase note about single IP addresses
This PR improves the phrasing of the note we have in the docs about using single IP addresses.


Patch:
diff --git a/internal/config/config.go b/internal/config/config.go
index f41c4266..866f8229 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -18,6 +18,7 @@ import (
 	"errors"
 	"fmt"
 	"net"
+	"reflect"
 	"strconv"
 	"strings"
 	"time"
@@ -200,6 +201,14 @@ func Parse(bs []byte) (*Config, error) {
 		if err != nil {
 			return nil, fmt.Errorf("parsing peer #%d: %s", i+1, err)
 		}
+		for _, ep := range cfg.Peers {
+			// TODO: Be smarter regarding conflicting peers. For example, two
+			// peers could have a different hold time but they'd still result
+			// in two BGP sessions between the speaker and the remote host.
+			if reflect.DeepEqual(peer, ep) {
+				return nil, fmt.Errorf("peer #%d already exists", i+1)
+			}
+		}
 		cfg.Peers = append(cfg.Peers, peer)
 	}
 
diff --git a/website/content/configuration/_index.md b/website/content/configuration/_index.md
index da8ed389..25909bb1 100644
--- a/website/content/configuration/_index.md
+++ b/website/content/configuration/_index.md
@@ -266,8 +266,8 @@ pool with the methods described in
 the [usage](/usage/#requesting-specific-ips) section.
 
 {{% notice note %}}
-Please note that if you have a single address pool, you must use `/32`
-CIDR notation (e.g. `42.176.25.64/32`).
+To specify a single IP address in a pool, use `/32` in the CIDR notation
+(e.g. `42.176.25.64/32`).
 {{% /notice %}}
 
 ### Handling buggy networks


Test patch:
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 2ff39125..0a50d10b 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -345,6 +345,19 @@ peers:
 `,
 		},
 
+		{
+			desc: "duplicate peers",
+			raw: `
+peers:
+- my-asn: 42
+  peer-asn: 42
+  peer-address: 1.2.3.4
+- my-asn: 42
+  peer-asn: 42
+  peer-address: 1.2.3.4
+`,
+		},
+
 		{
 			desc: "no pool name",
 			raw: `