Skip to content

Commit

Permalink
config: add tcp4only for lvs whitelist! (#21552)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylzd authored Dec 9, 2020
1 parent 6cd3c65 commit 5d9bb45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ type Config struct {
// where M is the element literal length and w is the number of bytes required for the maximum-length character in the character set.
// See https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html for more details.
EnableEnumLengthLimit bool `toml:"enable-enum-length-limit" json:"enable-enum-length-limit"`
// EnableTCP4Only enables net.Listen("tcp4",...)
// Note that: it can make lvs with toa work and thus tidb can get real client ip.
EnableTCP4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"`
}

// UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed
Expand Down
6 changes: 5 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {

if s.cfg.Host != "" && (s.cfg.Port != 0 || runInGoTest) {
addr := fmt.Sprintf("%s:%d", s.cfg.Host, s.cfg.Port)
if s.listener, err = net.Listen("tcp", addr); err == nil {
tcpProto := "tcp"
if s.cfg.EnableTCP4Only {
tcpProto = "tcp4"
}
if s.listener, err = net.Listen(tcpProto, addr); err == nil {
logutil.BgLogger().Info("server is running MySQL protocol", zap.String("addr", addr))
if cfg.Socket != "" {
if s.socket, err = net.Listen("unix", s.cfg.Socket); err == nil {
Expand Down

0 comments on commit 5d9bb45

Please sign in to comment.