Skip to content

Commit

Permalink
Clock matcher: use UTC by default
Browse files Browse the repository at this point in the history
  • Loading branch information
vnxme committed Aug 2, 2024
1 parent 1a2b15a commit 698448b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion layer4/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func WrapConnection(underlying net.Conn, buf []byte, logger *zap.Logger) *Connec
repl := caddy.NewReplacer()
repl.Set("l4.conn.remote_addr", underlying.RemoteAddr())
repl.Set("l4.conn.local_addr", underlying.LocalAddr())
repl.Set("l4.conn.wrap_time", time.Now())
repl.Set("l4.conn.wrap_time", time.Now().UTC())

ctx := context.Background()
ctx = context.WithValue(ctx, VarsCtxKey, make(map[string]interface{}))
Expand Down
11 changes: 5 additions & 6 deletions modules/l4clock/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (m *MatchClock) Match(cx *layer4.Connection) (bool, error) {
repl := cx.Context.Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
t, known := repl.Get(timeKey)
if !known {
t = time.Now()
t = time.Now().UTC()
repl.Set(timeKey, t)
}
secondsNow := timeToSeconds(t.(time.Time).In(m.location))
Expand All @@ -63,7 +63,7 @@ func (m *MatchClock) Match(cx *layer4.Connection) (bool, error) {
return false, nil
}

// Provision parses m's time points and a time zone (the system's local time zone is used by default).
// Provision parses m's time points and a time zone (UTC is used by default).
func (m *MatchClock) Provision(_ caddy.Context) (err error) {
repl := caddy.NewReplacer()

Expand All @@ -88,9 +88,7 @@ func (m *MatchClock) Provision(_ caddy.Context) (err error) {
}

timezone := repl.ReplaceAll(m.Timezone, "")
if timezone == "" {
m.location = time.Local
} else if m.location, err = time.LoadLocation(timezone); err != nil {
if m.location, err = time.LoadLocation(timezone); err != nil {
return
}

Expand All @@ -106,7 +104,8 @@ func (m *MatchClock) Provision(_ caddy.Context) (err error) {
// Note: MatchClock checks if time_now is greater than or equal to time_after AND less than time_before.
// The lowest value is 00:00:00. If time_before equals 00:00:00, it is treated as 24:00:00. If time_after is greater
// than time_before, they are swapped. Both "after 00:00:00" and "before 00:00:00" match all day. An IANA time zone
// location should be used as a value for time_zone. If time_zone is empty, the system's local time zone is used.
// location should be used as a value for time_zone. The system's local time zone may be used with "Local" value.
// If time_zone is empty, UTC is used.
func (m *MatchClock) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
_, wrapper := d.Next(), d.Val() // consume wrapper name

Expand Down

0 comments on commit 698448b

Please sign in to comment.