-
Notifications
You must be signed in to change notification settings - Fork 0
/
base-handler.go
42 lines (35 loc) · 990 Bytes
/
base-handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2023 Louis Royer and the NextMN-SRv6 contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT
package netfunc
import (
"net/netip"
)
// Use this as a base for new handlers
type BaseHandler struct {
prefix netip.Prefix
ttl uint8
hopLimit uint8
}
func NewBaseHandler(prefix netip.Prefix, ttl uint8, hopLimit uint8) BaseHandler {
return BaseHandler{
prefix: prefix,
ttl: ttl,
hopLimit: hopLimit,
}
}
// Return prefix of the Handler as a *netip.Prefix
func (h BaseHandler) Prefix() netip.Prefix {
return h.prefix
}
func (h BaseHandler) TTL() uint8 {
return h.ttl
}
func (h BaseHandler) HopLimit() uint8 {
return h.hopLimit
}
// Return nil if the packet IP destination address (first network layer) is in the prefix range
func (h BaseHandler) CheckDAInPrefixRange(pqt *Packet) error {
return pqt.CheckDAInPrefixRange(h.Prefix())
}