mirror of
https://github.com/daeuniverse/dae.git
synced 2025-02-02 04:14:31 +07:00
fix: No AddrPort presented for LAN
This commit is contained in:
parent
384b4131a3
commit
ea340372b8
@ -533,9 +533,10 @@ func (c *ControlPlane) ListenAndServe(port uint16) (err error) {
|
|||||||
routingResult, err := c.core.RetrieveRoutingResult(src, pktDst, unix.IPPROTO_UDP)
|
routingResult, err := c.core.RetrieveRoutingResult(src, pktDst, unix.IPPROTO_UDP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// WAN. Old method.
|
// WAN. Old method.
|
||||||
|
lastErr := err
|
||||||
addrHdr, dataOffset, err := ParseAddrHdr(data)
|
addrHdr, dataOffset, err := ParseAddrHdr(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Warnf("No AddrPort presented: %v", err)
|
c.log.Warnf("No AddrPort presented: %v, %v", lastErr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
copy(data, data[dataOffset:])
|
copy(data, data[dataOffset:])
|
||||||
|
@ -158,7 +158,7 @@ struct {
|
|||||||
// side does not care it (full-cone).
|
// side does not care it (full-cone).
|
||||||
__type(value, struct dst_routing_result); // Original target.
|
__type(value, struct dst_routing_result); // Original target.
|
||||||
__uint(max_entries, MAX_DST_MAPPING_NUM);
|
__uint(max_entries, MAX_DST_MAPPING_NUM);
|
||||||
/// NOTICE: It MUST be pinned.
|
/// NOTICE: It MUST be pinned, or connection may break.
|
||||||
__uint(pinning, LIBBPF_PIN_BY_NAME);
|
__uint(pinning, LIBBPF_PIN_BY_NAME);
|
||||||
} tcp_dst_map
|
} tcp_dst_map
|
||||||
SEC(".maps"); // This map is only for old method (redirect mode in WAN).
|
SEC(".maps"); // This map is only for old method (redirect mode in WAN).
|
||||||
@ -187,7 +187,6 @@ struct {
|
|||||||
__type(key, __u32);
|
__type(key, __u32);
|
||||||
__type(value, struct lpm_key);
|
__type(value, struct lpm_key);
|
||||||
__uint(max_entries, 3);
|
__uint(max_entries, 3);
|
||||||
__uint(pinning, LIBBPF_PIN_BY_NAME);
|
|
||||||
} lpm_key_map SEC(".maps");
|
} lpm_key_map SEC(".maps");
|
||||||
|
|
||||||
// h_sport, h_dport:
|
// h_sport, h_dport:
|
||||||
@ -196,7 +195,6 @@ struct {
|
|||||||
__type(key, __u32);
|
__type(key, __u32);
|
||||||
__type(value, __u16);
|
__type(value, __u16);
|
||||||
__uint(max_entries, 2);
|
__uint(max_entries, 2);
|
||||||
__uint(pinning, LIBBPF_PIN_BY_NAME);
|
|
||||||
} h_port_map SEC(".maps");
|
} h_port_map SEC(".maps");
|
||||||
|
|
||||||
// l4proto, ipversion:
|
// l4proto, ipversion:
|
||||||
@ -205,7 +203,6 @@ struct {
|
|||||||
__type(key, __u32);
|
__type(key, __u32);
|
||||||
__type(value, __u32);
|
__type(value, __u32);
|
||||||
__uint(max_entries, 2);
|
__uint(max_entries, 2);
|
||||||
__uint(pinning, LIBBPF_PIN_BY_NAME);
|
|
||||||
} l4proto_ipversion_map SEC(".maps");
|
} l4proto_ipversion_map SEC(".maps");
|
||||||
|
|
||||||
// IPPROTO to hdr_size
|
// IPPROTO to hdr_size
|
||||||
@ -1763,8 +1760,9 @@ int tproxy_wan_egress(struct __sk_buff *skb) {
|
|||||||
|
|
||||||
if ((new_hdr.routing_result.outbound == OUTBOUND_DIRECT ||
|
if ((new_hdr.routing_result.outbound == OUTBOUND_DIRECT ||
|
||||||
new_hdr.routing_result.outbound == OUTBOUND_MUST_DIRECT) &&
|
new_hdr.routing_result.outbound == OUTBOUND_MUST_DIRECT) &&
|
||||||
new_hdr.routing_result.mark == 0 // If mark is not zero, we should re-route it, so we
|
new_hdr.routing_result.mark ==
|
||||||
// send it to control plane in WAN.
|
0 // If mark is not zero, we should re-route it, so we
|
||||||
|
// send it to control plane in WAN.
|
||||||
) {
|
) {
|
||||||
return TC_ACT_OK;
|
return TC_ACT_OK;
|
||||||
} else if (unlikely(new_hdr.routing_result.outbound == OUTBOUND_BLOCK)) {
|
} else if (unlikely(new_hdr.routing_result.outbound == OUTBOUND_BLOCK)) {
|
||||||
|
@ -32,7 +32,7 @@ func (c *ControlPlaneCore) RetrieveRoutingResult(src, dst netip.AddrPort, l4prot
|
|||||||
}
|
}
|
||||||
|
|
||||||
var routingResult bpfRoutingResult
|
var routingResult bpfRoutingResult
|
||||||
if err := c.bpf.RoutingTuplesMap.LookupAndDelete(tuples, &routingResult); err != nil {
|
if err := c.bpf.RoutingTuplesMap.Lookup(tuples, &routingResult); err != nil {
|
||||||
return nil, fmt.Errorf("reading map: key [%v, %v, %v]: %w", src.String(), l4proto, dst.String(), err)
|
return nil, fmt.Errorf("reading map: key [%v, %v, %v]: %w", src.String(), l4proto, dst.String(), err)
|
||||||
}
|
}
|
||||||
return &routingResult, nil
|
return &routingResult, nil
|
||||||
@ -97,10 +97,12 @@ func ProcessName2String(pname []uint8) string {
|
|||||||
func Mac2String(mac []uint8) string {
|
func Mac2String(mac []uint8) string {
|
||||||
ori := []byte(hex.EncodeToString(mac))
|
ori := []byte(hex.EncodeToString(mac))
|
||||||
// Insert ":".
|
// Insert ":".
|
||||||
b := make([]byte, len(ori)/2*3)
|
b := make([]byte, len(ori)/2*3-1)
|
||||||
for i, j := 0, 0; i < len(ori); i, j = i+2, j+3 {
|
for i, j := 0, 0; i < len(ori); i, j = i+2, j+3 {
|
||||||
copy(b[j:j+2], ori[i:i+2])
|
copy(b[j:j+2], ori[i:i+2])
|
||||||
b[j+2] = ':'
|
if j+2 < len(b) {
|
||||||
|
b[j+2] = ':'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user