Skip to content

Commit bd7330e

Browse files
authored
make media and signaling possible use different ips (#323)
1 parent a61278a commit bd7330e

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

pkg/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ type Config struct {
7878
NAT1To1IP string `yaml:"nat_1_to_1_ip"`
7979
ListenIP string `yaml:"listen_ip"`
8080

81+
// if different from signaling IP
82+
MediaUseExternalIP bool `yaml:"media_use_external_ip"`
83+
MediaNAT1To1IP string `yaml:"media_nat_1_to_1_ip"`
84+
8185
MediaTimeout time.Duration `yaml:"media_timeout"`
8286
MediaTimeoutInitial time.Duration `yaml:"media_timeout_initial"`
8387
Codecs map[string]bool `yaml:"codecs"`
@@ -151,6 +155,10 @@ func (c *Config) Init() error {
151155
return fmt.Errorf("use_external_ip and nat_1_to_1_ip can not both be set")
152156
}
153157

158+
if c.MediaUseExternalIP && c.MediaNAT1To1IP != "" {
159+
return fmt.Errorf("media_use_external_ip and media_nat_1_to_1_ip can not both be set")
160+
}
161+
154162
return nil
155163
}
156164

pkg/sip/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ func GetServiceConfig(conf *config.Config) (*ServiceConfig, error) {
4848
}
4949
s.SignalingIPLocal = s.SignalingIP
5050
}
51+
if conf.MediaUseExternalIP && !conf.UseExternalIP {
52+
if s.MediaIP, err = getPublicIP(); err != nil {
53+
return nil, err
54+
}
55+
} else if conf.MediaNAT1To1IP != "" && conf.MediaNAT1To1IP != conf.NAT1To1IP {
56+
ip, err := netip.ParseAddr(conf.MediaNAT1To1IP)
57+
if err != nil {
58+
return nil, err
59+
}
60+
s.MediaIP = ip
61+
} else {
62+
s.MediaIP = s.SignalingIP
63+
}
5164
return s, nil
5265
}
5366

pkg/sip/inbound.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func (c *inboundCall) runMediaConn(offerData []byte, conf *config.Config, featur
541541
c.log.Debugw("SDP offer", "sdp", string(offerData))
542542

543543
mp, err := NewMediaPort(c.log, c.mon, &MediaConfig{
544-
IP: c.s.sconf.SignalingIP,
544+
IP: c.s.sconf.MediaIP,
545545
Ports: conf.RTPPort,
546546
MediaTimeoutInitial: c.s.conf.MediaTimeoutInitial,
547547
MediaTimeout: c.s.conf.MediaTimeout,

pkg/sip/outbound.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (c *Client) newCall(ctx context.Context, conf *config.Config, log logger.Lo
118118
var err error
119119

120120
call.media, err = NewMediaPort(call.log, call.mon, &MediaConfig{
121-
IP: c.sconf.SignalingIP,
121+
IP: c.sconf.MediaIP,
122122
Ports: conf.RTPPort,
123123
MediaTimeoutInitial: c.conf.MediaTimeoutInitial,
124124
MediaTimeout: c.conf.MediaTimeout,

pkg/sip/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
type ServiceConfig struct {
4040
SignalingIP netip.Addr
4141
SignalingIPLocal netip.Addr
42+
MediaIP netip.Addr
4243
}
4344

4445
type Service struct {

0 commit comments

Comments
 (0)