diff --git a/cmd/internal/subscription.go b/cmd/internal/subscription.go index a3226ae..721067e 100644 --- a/cmd/internal/subscription.go +++ b/cmd/internal/subscription.go @@ -81,6 +81,15 @@ func resolveSubscriptionAsSIP008(log *logrus.Logger, b []byte) (nodes []string, } 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) resp, err := http.Get(subscription) if err != nil { diff --git a/control/bpf_utils.go b/control/bpf_utils.go index dafeaa4..05de0fe 100644 --- a/control/bpf_utils.go +++ b/control/bpf_utils.go @@ -50,7 +50,7 @@ func (o *bpfObjects) newLpmMap(keys []_bpfLpmKey, values []uint32) (m *ebpf.Map, if err != nil { return nil, err } - if _, err = BatchUpdate(m, keys, values, &ebpf.BatchOptions{ + if _, err = BpfMapBatchUpdate(m, keys, values, &ebpf.BatchOptions{ ElemFlags: uint64(ebpf.UpdateAny), }); err != nil { return nil, err @@ -76,7 +76,7 @@ var ( 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() { version, e := internal.KernelVersion() if e != nil { @@ -98,7 +98,7 @@ func BatchUpdate(m *ebpf.Map, keys interface{}, values interface{}, opts *ebpf.B } if !simulate { - // Genuine BatchUpdate + // Genuine BpfMapBatchUpdate return m.BatchUpdate(keys, values, opts) } diff --git a/control/dns.go b/control/dns.go index f222fe9..7096ba5 100644 --- a/control/dns.go +++ b/control/dns.go @@ -38,9 +38,10 @@ func (c *dnsCache) FillInto(req *dnsmessage.Message) { // Align question and answer Name. if len(req.Questions) > 0 { q := req.Questions[0] - if len(req.Answers) > 0 && - strings.EqualFold(req.Answers[0].Header.Name.String(), q.Name.String()) { - req.Answers[0].Header.Name.Data = q.Name.Data + for i := range req.Answers { + if strings.EqualFold(req.Answers[i].Header.Name.String(), q.Name.String()) { + req.Answers[i].Header.Name.Data = q.Name.Data + } } } req.RCode = dnsmessage.RCodeSuccess @@ -64,7 +65,7 @@ func (c *ControlPlane) BatchUpdateDomainRouting(cache *dnsCache) error { } // Update bpf map. - // Construct keys and vals, and BatchUpdate. + // Construct keys and vals, and BpfMapBatchUpdate. var keys [][4]uint32 var vals []bpfDomainRouting for _, ip := range ips { @@ -74,7 +75,7 @@ func (c *ControlPlane) BatchUpdateDomainRouting(cache *dnsCache) error { 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), }); err != nil { return err @@ -205,9 +206,10 @@ func (c *ControlPlane) DnsRespHandler(data []byte, validateRushAns bool) (newDat FlipDnsQuestionCase(&msg) q := msg.Questions[0] // Align Name. - if len(msg.Answers) > 0 && - strings.EqualFold(msg.Answers[0].Header.Name.String(), q.Name.String()) { - msg.Answers[0].Header.Name.Data = q.Name.Data + for i := range msg.Answers { + if strings.EqualFold(msg.Answers[i].Header.Name.String(), q.Name.String()) { + msg.Answers[i].Header.Name.Data = q.Name.Data + } } for i := range msg.Additionals { if strings.EqualFold(msg.Additionals[i].Header.Name.String(), q.Name.String()) { diff --git a/control/routing_matcher_builder.go b/control/routing_matcher_builder.go index 5196cc7..7a50c04 100644 --- a/control/routing_matcher_builder.go +++ b/control/routing_matcher_builder.go @@ -240,7 +240,7 @@ func (b *RoutingMatcherBuilder) Build() (err error) { if err != nil { 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 { m.Close() return fmt.Errorf("Update: %w", err) @@ -255,10 +255,10 @@ func (b *RoutingMatcherBuilder) Build() (err error) { } routingsLen := uint32(len(b.rules)) 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), }); err != nil { - return fmt.Errorf("BatchUpdate: %w", err) + return fmt.Errorf("BpfMapBatchUpdate: %w", err) } return nil }