Changeset 370 in code for trunk/config/config.go
- Timestamp:
- Jul 22, 2020, 3:03:01 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/config.go
r323 r370 5 5 "fmt" 6 6 "io" 7 "net" 7 8 "os" 8 9 9 10 "github.com/google/shlex" 10 11 ) 12 13 type IPSet []*net.IPNet 14 15 func (set IPSet) Contains(ip net.IP) bool { 16 for _, n := range set { 17 if n.Contains(ip) { 18 return true 19 } 20 } 21 return false 22 } 23 24 // loopbackIPs contains the loopback networks 127.0.0.0/8 and ::1/128. 25 var loopbackIPs = IPSet{ 26 &net.IPNet{ 27 IP: net.IP{127, 0, 0, 0}, 28 Mask: net.CIDRMask(8, 32), 29 }, 30 &net.IPNet{ 31 IP: net.IPv6loopback, 32 Mask: net.CIDRMask(128, 128), 33 }, 34 } 11 35 12 36 type TLS struct { … … 15 39 16 40 type Server struct { 17 Listen []string 18 Hostname string 19 TLS *TLS 20 SQLDriver string 21 SQLSource string 22 LogPath string 23 HTTPOrigins []string 41 Listen []string 42 Hostname string 43 TLS *TLS 44 SQLDriver string 45 SQLSource string 46 LogPath string 47 HTTPOrigins []string 48 AcceptProxyIPs IPSet 24 49 } 25 50 … … 30 55 } 31 56 return &Server{ 32 Hostname: hostname, 33 SQLDriver: "sqlite3", 34 SQLSource: "soju.db", 57 Hostname: hostname, 58 SQLDriver: "sqlite3", 59 SQLSource: "soju.db", 60 AcceptProxyIPs: loopbackIPs, 35 61 } 36 62 } … … 94 120 case "http-origin": 95 121 srv.HTTPOrigins = append(srv.HTTPOrigins, d.Params...) 122 case "accept-proxy-ip": 123 srv.AcceptProxyIPs = nil 124 for _, s := range d.Params { 125 _, n, err := net.ParseCIDR(s) 126 if err != nil { 127 return nil, fmt.Errorf("directive %q: failed to parse CIDR: %v", d.Name, err) 128 } 129 srv.AcceptProxyIPs = append(srv.AcceptProxyIPs, n) 130 } 96 131 default: 97 132 return nil, fmt.Errorf("unknown directive %q", d.Name)
Note:
See TracChangeset
for help on using the changeset viewer.