diff --git a/config-sample.yaml b/config-sample.yaml index a75b5736..143e8f0d 100644 --- a/config-sample.yaml +++ b/config-sample.yaml @@ -75,13 +75,20 @@ rtc: # high_quality: 1s # # network interface filter. If the machine has more than one network interface and you'd like it to use or skip specific interfaces # # both inclusion and exclusion filters can be used together. If neither is defined (default), all interfaces on the machine will be used. - # # If both of them are set, then only interfaces that satisfy both filters will be used. - # # If an interface is present in both lists, include takes precedence. + # # If both of them are set, then only include takes effect. # interfaces: # includes: # - en0 # excludes: # - docker0 + # # ip address filter. If the machine has more than one ip address and you'd like it to use or skip specific ips, + # # both inclusion and exclusion CIDR filters can be used together. If neither is defined (default), all ip on the machine will be used. + # # If both of them are set, then only include takes effect. + # ips: + # includes: + # - 10.0.0.0/16 + # excludes: + # - 192.168.1.0/24 # when enabled, LiveKit will expose prometheus metrics on :6789/metrics # prometheus_port: 6789 diff --git a/go.mod b/go.mod index 414e8e2e..e5ce2353 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0 github.com/mitchellh/go-homedir v1.1.0 github.com/olekukonko/tablewriter v0.0.5 - github.com/pion/ice/v2 v2.2.9 + github.com/pion/ice/v2 v2.2.10 github.com/pion/interceptor v0.1.12 github.com/pion/logging v0.2.2 github.com/pion/rtcp v1.2.10 @@ -33,7 +33,7 @@ require ( github.com/pion/stun v0.3.5 github.com/pion/transport v0.13.1 github.com/pion/turn/v2 v2.0.8 - github.com/pion/webrtc/v3 v3.1.45 + github.com/pion/webrtc/v3 v3.1.46 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.13.0 github.com/rs/cors v1.8.2 @@ -85,10 +85,10 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.uber.org/multierr v1.6.0 // indirect - golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 // indirect + golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect - golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect - golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect + golang.org/x/net v0.0.0-20220927171203-f486391704dc // indirect + golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.10 // indirect golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect diff --git a/go.sum b/go.sum index 1d65e41f..ff78b97e 100644 --- a/go.sum +++ b/go.sum @@ -304,9 +304,8 @@ github.com/pion/dtls/v2 v2.1.3/go.mod h1:o6+WvyLDAlXF7YiPB/RlskRoeK+/JtuaZa5emwQ github.com/pion/dtls/v2 v2.1.5 h1:jlh2vtIyUBShchoTDqpCCqiYCyRFJ/lvf/gQ8TALs+c= github.com/pion/dtls/v2 v2.1.5/go.mod h1:BqCE7xPZbPSubGasRoDFJeTsyJtdD1FanJYL0JGheqY= github.com/pion/ice/v2 v2.2.6/go.mod h1:SWuHiOGP17lGromHTFadUe1EuPgFh/oCU6FCMZHooVE= -github.com/pion/ice/v2 v2.2.8/go.mod h1:J6HhupoMLTOv0yALipuOHEPoSMk7dm1ofwUI1KHVHk8= -github.com/pion/ice/v2 v2.2.9 h1:7MT82FJ9pYxSumXfMvNpN6if7jhIyRM1GBo95qw+Yi8= -github.com/pion/ice/v2 v2.2.9/go.mod h1:J6HhupoMLTOv0yALipuOHEPoSMk7dm1ofwUI1KHVHk8= +github.com/pion/ice/v2 v2.2.10 h1:i8rn0iIN8wHlS9wosoHS3Du4hYwx+TjBEluisXYtQVE= +github.com/pion/ice/v2 v2.2.10/go.mod h1:J6HhupoMLTOv0yALipuOHEPoSMk7dm1ofwUI1KHVHk8= github.com/pion/interceptor v0.1.11/go.mod h1:tbtKjZY14awXd7Bq0mmWvgtHB5MDaRN7HV3OZ/uy7s8= github.com/pion/interceptor v0.1.12 h1:CslaNriCFUItiXS5o+hh5lpL0t0ytQkFnUcbbCs2Zq8= github.com/pion/interceptor v0.1.12/go.mod h1:bDtgAD9dRkBZpWHGKaoKb42FhDHTG2rX8Ii9LRALLVA= @@ -341,8 +340,8 @@ github.com/pion/turn/v2 v2.0.8/go.mod h1:+y7xl719J8bAEVpSXBXvTxStjJv3hbz9YFflvkp github.com/pion/udp v0.1.1 h1:8UAPvyqmsxK8oOjloDk4wUt63TzFe9WEJkg5lChlj7o= github.com/pion/udp v0.1.1/go.mod h1:6AFo+CMdKQm7UiA0eUPA8/eVCTx8jBIITLZHc9DWX5M= github.com/pion/webrtc/v3 v3.1.44/go.mod h1:G/J8k0+grVsjC/rjCZ24AKoCCxcFFODgh7zThNZGs0M= -github.com/pion/webrtc/v3 v3.1.45 h1:pJpD9TSMqtWIAGKXmpRhFmsQrrMlNgRx0UX1fGHbfoY= -github.com/pion/webrtc/v3 v3.1.45/go.mod h1:kzR63aagkyrJgxjAaI/Mbig/RiN2Bne7pDrze/uyLrs= +github.com/pion/webrtc/v3 v3.1.46 h1:SY1DsOY/wT6NhufhkDX1z6DJtaRsKIzZi/qWPWSpC6c= +github.com/pion/webrtc/v3 v3.1.46/go.mod h1:LH719CtoMgU8Ik+7J9Ey9lYbOdHZk/cJ2stoe6NzDnM= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -447,8 +446,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220516162934-403b01795ae8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 h1:WJywXQVIb56P2kAvXeMGTIgQ1ZHQxR60+F9dLsodECc= -golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be h1:fmw3UbQh+nxngCAHrDCCztao/kbYFnWjoqop8dHx05A= +golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -536,8 +535,8 @@ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220531201128-c960675eff93/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220630215102-69896b714898/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/net v0.0.0-20220923203811-8be639271d50 h1:vKyz8L3zkd+xrMeIaBsQ/MNVPVFSffdaU3ZyYlBGFnI= -golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.0.0-20220927171203-f486391704dc h1:FxpXZdoBqT8RjqTy6i1E8nXHhW21wK7ptQ/EPIGxzPQ= +golang.org/x/net v0.0.0-20220927171203-f486391704dc/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -627,8 +626,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/pkg/config/config.go b/pkg/config/config.go index f95b9af4..e295f221 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -64,6 +64,7 @@ type RTCConfig struct { UseExternalIP bool `yaml:"use_external_ip"` UseICELite bool `yaml:"use_ice_lite,omitempty"` Interfaces InterfacesConfig `yaml:"interfaces"` + IPs IPsConfig `yaml:"ips"` // Number of packets to buffer for NACK PacketBufferSize int `yaml:"packet_buffer_size,omitempty"` @@ -107,6 +108,11 @@ type InterfacesConfig struct { Excludes []string `yaml:"excludes"` } +type IPsConfig struct { + Includes []string `yaml:"includes"` + Excludes []string `yaml:"excludes"` +} + type AudioConfig struct { // minimum level to be considered active, 0-127, where 0 is loudest ActiveLevel uint8 `yaml:"active_level"` diff --git a/pkg/rtc/config.go b/pkg/rtc/config.go index 06dee157..0d2c97df 100644 --- a/pkg/rtc/config.go +++ b/pkg/rtc/config.go @@ -227,6 +227,49 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err }) } + if len(rtcConf.IPs.Includes) != 0 || len(rtcConf.IPs.Excludes) != 0 { + var ipnets [2][]*net.IPNet + for i, ips := range [][]string{rtcConf.IPs.Includes, rtcConf.IPs.Excludes} { + ipnets[i], err = func(fromIPs []string) ([]*net.IPNet, error) { + var toNets []*net.IPNet + for _, ip := range fromIPs { + _, ipnet, err := net.ParseCIDR(ip) + if err != nil { + return nil, err + } + toNets = append(toNets, ipnet) + } + return toNets, nil + }(ips) + + if err != nil { + return nil, err + } + } + + includes, excludes := ipnets[0], ipnets[1] + + s.SetIPFilter(func(ip net.IP) bool { + if len(includes) > 0 { + for _, ipn := range includes { + if ipn.Contains(ip) { + return true + } + } + return false + } + + if len(excludes) > 0 { + for _, ipn := range excludes { + if ipn.Contains(ip) { + return false + } + } + } + return true + }) + } + return &WebRTCConfig{ Configuration: c, SettingEngine: s,