mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-15 10:18:45 +07:00
fix: align all dns resp answer headers
This commit is contained in:
@ -81,6 +81,15 @@ func resolveSubscriptionAsSIP008(log *logrus.Logger, b []byte) (nodes []string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ResolveSubscription(log *logrus.Logger, subscription string) (nodes []string, err error) {
|
func ResolveSubscription(log *logrus.Logger, subscription string) (nodes []string, err error) {
|
||||||
|
u, err := url.Parse(subscription)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse subscription \"%v\": %w", subscription, err)
|
||||||
|
}
|
||||||
|
switch u.Scheme {
|
||||||
|
case "file":
|
||||||
|
// TODO
|
||||||
|
default:
|
||||||
|
}
|
||||||
log.Debugf("ResolveSubscription: %v", subscription)
|
log.Debugf("ResolveSubscription: %v", subscription)
|
||||||
resp, err := http.Get(subscription)
|
resp, err := http.Get(subscription)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,7 @@ func (o *bpfObjects) newLpmMap(keys []_bpfLpmKey, values []uint32) (m *ebpf.Map,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err = BatchUpdate(m, keys, values, &ebpf.BatchOptions{
|
if _, err = BpfMapBatchUpdate(m, keys, values, &ebpf.BatchOptions{
|
||||||
ElemFlags: uint64(ebpf.UpdateAny),
|
ElemFlags: uint64(ebpf.UpdateAny),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -76,7 +76,7 @@ var (
|
|||||||
SimulateBatchUpdateLpmTrie bool
|
SimulateBatchUpdateLpmTrie bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func BatchUpdate(m *ebpf.Map, keys interface{}, values interface{}, opts *ebpf.BatchOptions) (n int, err error) {
|
func BpfMapBatchUpdate(m *ebpf.Map, keys interface{}, values interface{}, opts *ebpf.BatchOptions) (n int, err error) {
|
||||||
CheckBatchUpdateFeatureOnce.Do(func() {
|
CheckBatchUpdateFeatureOnce.Do(func() {
|
||||||
version, e := internal.KernelVersion()
|
version, e := internal.KernelVersion()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@ -98,7 +98,7 @@ func BatchUpdate(m *ebpf.Map, keys interface{}, values interface{}, opts *ebpf.B
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !simulate {
|
if !simulate {
|
||||||
// Genuine BatchUpdate
|
// Genuine BpfMapBatchUpdate
|
||||||
return m.BatchUpdate(keys, values, opts)
|
return m.BatchUpdate(keys, values, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +38,10 @@ func (c *dnsCache) FillInto(req *dnsmessage.Message) {
|
|||||||
// Align question and answer Name.
|
// Align question and answer Name.
|
||||||
if len(req.Questions) > 0 {
|
if len(req.Questions) > 0 {
|
||||||
q := req.Questions[0]
|
q := req.Questions[0]
|
||||||
if len(req.Answers) > 0 &&
|
for i := range req.Answers {
|
||||||
strings.EqualFold(req.Answers[0].Header.Name.String(), q.Name.String()) {
|
if strings.EqualFold(req.Answers[i].Header.Name.String(), q.Name.String()) {
|
||||||
req.Answers[0].Header.Name.Data = q.Name.Data
|
req.Answers[i].Header.Name.Data = q.Name.Data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req.RCode = dnsmessage.RCodeSuccess
|
req.RCode = dnsmessage.RCodeSuccess
|
||||||
@ -64,7 +65,7 @@ func (c *ControlPlane) BatchUpdateDomainRouting(cache *dnsCache) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update bpf map.
|
// Update bpf map.
|
||||||
// Construct keys and vals, and BatchUpdate.
|
// Construct keys and vals, and BpfMapBatchUpdate.
|
||||||
var keys [][4]uint32
|
var keys [][4]uint32
|
||||||
var vals []bpfDomainRouting
|
var vals []bpfDomainRouting
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
@ -74,7 +75,7 @@ func (c *ControlPlane) BatchUpdateDomainRouting(cache *dnsCache) error {
|
|||||||
Bitmap: cache.DomainBitmap,
|
Bitmap: cache.DomainBitmap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if _, err := BatchUpdate(c.core.bpf.DomainRoutingMap, keys, vals, &ebpf.BatchOptions{
|
if _, err := BpfMapBatchUpdate(c.core.bpf.DomainRoutingMap, keys, vals, &ebpf.BatchOptions{
|
||||||
ElemFlags: uint64(ebpf.UpdateAny),
|
ElemFlags: uint64(ebpf.UpdateAny),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -205,9 +206,10 @@ func (c *ControlPlane) DnsRespHandler(data []byte, validateRushAns bool) (newDat
|
|||||||
FlipDnsQuestionCase(&msg)
|
FlipDnsQuestionCase(&msg)
|
||||||
q := msg.Questions[0]
|
q := msg.Questions[0]
|
||||||
// Align Name.
|
// Align Name.
|
||||||
if len(msg.Answers) > 0 &&
|
for i := range msg.Answers {
|
||||||
strings.EqualFold(msg.Answers[0].Header.Name.String(), q.Name.String()) {
|
if strings.EqualFold(msg.Answers[i].Header.Name.String(), q.Name.String()) {
|
||||||
msg.Answers[0].Header.Name.Data = q.Name.Data
|
msg.Answers[i].Header.Name.Data = q.Name.Data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for i := range msg.Additionals {
|
for i := range msg.Additionals {
|
||||||
if strings.EqualFold(msg.Additionals[i].Header.Name.String(), q.Name.String()) {
|
if strings.EqualFold(msg.Additionals[i].Header.Name.String(), q.Name.String()) {
|
||||||
|
@ -240,7 +240,7 @@ func (b *RoutingMatcherBuilder) Build() (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("newLpmMap: %w", err)
|
return fmt.Errorf("newLpmMap: %w", err)
|
||||||
}
|
}
|
||||||
// ebpf.Map cannot be BatchUpdate
|
// We cannot invoke BpfMapBatchUpdate when value is ebpf.Map.
|
||||||
if err = b.bpf.LpmArrayMap.Update(uint32(i), m, ebpf.UpdateAny); err != nil {
|
if err = b.bpf.LpmArrayMap.Update(uint32(i), m, ebpf.UpdateAny); err != nil {
|
||||||
m.Close()
|
m.Close()
|
||||||
return fmt.Errorf("Update: %w", err)
|
return fmt.Errorf("Update: %w", err)
|
||||||
@ -255,10 +255,10 @@ func (b *RoutingMatcherBuilder) Build() (err error) {
|
|||||||
}
|
}
|
||||||
routingsLen := uint32(len(b.rules))
|
routingsLen := uint32(len(b.rules))
|
||||||
routingsKeys := common.ARangeU32(routingsLen)
|
routingsKeys := common.ARangeU32(routingsLen)
|
||||||
if _, err = BatchUpdate(b.bpf.RoutingMap, routingsKeys, b.rules, &ebpf.BatchOptions{
|
if _, err = BpfMapBatchUpdate(b.bpf.RoutingMap, routingsKeys, b.rules, &ebpf.BatchOptions{
|
||||||
ElemFlags: uint64(ebpf.UpdateAny),
|
ElemFlags: uint64(ebpf.UpdateAny),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("BatchUpdate: %w", err)
|
return fmt.Errorf("BpfMapBatchUpdate: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user