LLVM ERROR with reading names of a dns packet
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
Part of my bachelor thesis is to obtain the names of a dns question. As i got some errors when trying to print them with bpf_trace_print I thought it would be a better way to write them into a map and print them on the python side.
But with my code i get somehow the following LLVM ERROR. Im not sure if this is a bug in bcc or a bug in my code. I read something about #188, but another issues, says this has been fixed in December.
```
LLVM ERROR: Cannot select: 0x1ea6d90: ch,glue = BPFISD::CALL 0x1ea6c68, 0x1ea68f0, 0x1ed2ed0, 0x1dcd680, 0x1ec7398, 0x1ea6c68:1 [ORD=7] [ID=25]
0x1ea68f0: i64 = TargetExternalSymbol'memset' [ID=10]
0x1ed2ed0: i64 = Register %R1 [ID=7]
0x1dcd680: i64 = Register %R2 [ID=8]
0x1ec7398: i64 = Register %R3 [ID=9]
0x1ea6c68: ch,glue = CopyToReg 0x1ea60d8, 0x1ec7398, 0x168ca38, 0x1ea60d8:1 [ORD=7] [ID=24]
0x1ec7398: i64 = Register %R3 [ID=9]
0x168ca38: i64 = add 0x1ec7cd8, 0x1ed3498 [ORD=6] [ID=21]
0x1ec7cd8: i64 = and 0x1ed3120, 0x1ed3938 [ORD=5] [ID=19]
0x1ed3120: i64 = sub 0x1d78c10, 0x1d78d38 [ORD=4] [ID=17]
0x1d78c10: i64 = Constant<28> [ID=12]
0x1d78d38: i64 = AssertSext 0x1ea6450, 0x1dccf90 [ORD=2] [ID=16]
0x1ea6450: i64,ch = CopyFromReg 0x168a420, 0x1ec7a88 [ORD=2] [ID=13]
0x1ec7a88: i64 = Register %vreg6 [ID=1]
0x1ed3938: i64 = Constant<65535> [ID=11]
0x1ed3498: i64 = Constant<1> [ID=4]
0x1ea60d8: ch,glue = CopyToReg 0x1d78f88, 0x1dcd680, 0x168cc88, 0x1d78f88:1 [ORD=7] [ID=23]
0x1dcd680: i64 = Register %R2 [ID=8]
0x168cc88: i64 = Constant<0> [ID=5]
0x1d78f88: ch,glue = CopyToReg 0x1d791d8, 0x1ed2ed0, 0x1d78898 [ORD=7] [ID=22]
0x1ed2ed0: i64 = Register %R1 [ID=7]
0x1d78898: i64 = add 0x1ed35c0, 0x1ea6578 [ORD=3] [ID=20]
0x1ed35c0: i64,ch = CopyFromReg 0x168a420, 0x1d78e60 [ORD=3] [ID=14]
0x1d78e60: i64 = Register %vreg5 [ID=3]
0x1ea6578: i64 = and 0x1d78d38, 0x1ed3938 [ORD=2] [ID=18]
0x1d78d38: i64 = AssertSext 0x1ea6450, 0x1dccf90 [ORD=2] [ID=16]
0x1ea6450: i64,ch = CopyFromReg 0x168a420, 0x1ec7a88 [ORD=2] [ID=13]
0x1ec7a88: i64 = Register %vreg6 [ID=1]
0x1ed3938: i64 = Constant<65535> [ID=11]
In function: dns_test
```
My Code is as follow:
```
#include
#include
#include
#include
#include
#include
#include
#define ETH_LEN 14
struct dns_hdr_t
{
uint16_t id;
uint16_t flags;
/* number of entries in the question section */
uint16_t qdcount;
/* number of resource records in the answer section */
uint16_t ancount;
/* number of name server resource records in the authority records section*/
uint16_t nscount;
/* number of resource records in the additional records section */
uint16_t arcount;
} BPF_PACKET_HEADER;
struct dns_query_t
{
unsigned char *name;
unsigned short qtype;
unsigned short qclass;
} BPF_PACKET_HEADER;
struct Key {
u32 src_ip;
u16 id;
};
struct Leaf {
unsigned char p[30];
};
BPF_TABLE("hash", struct Key, struct Leaf, incoming, 1024);
int dns_test(struct __sk_buff *skb)
{
u8 *cursor = 0;
u32 udp_header_length = 0;
u32 ip_header_length = 0;
u32 offset = 0;
u32 len = 0;
struct Key key;
struct Leaf zLeaf = {};
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
if(ethernet->type == ETH_P_IP) {
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
if(ip->nextp == IPPROTO_UDP) {
// Add Key just for now based on src_ip and ip id.
key.src_ip = ip->src;
key.id = ip->identification;
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
if(udp->dport == 53){
struct dns_hdr_t *dns_hdr = cursor_advance(cursor, sizeof(*dns_hdr));
if((dns_hdr->flags >>15) != 0) {
// Exit if this packet is not a request.
return 0;
}
ip_header_length = ip->hlen << 2;
udp_header_length = 8;
offset = ETH_HLEN + ip_header_length + udp_header_length + sizeof(dns_hdr);
len = udp->length - udp_header_length - 16;
u16 p = 0;
struct Leaf *leaf = incoming.lookup_or_init(&key, &zLeaf);
for(u16 i = 0; i < 10; i++) {
if(i >=len) {
break;
}
leaf->p[p++] = bpf_dext_pkt(skb, offset + i, 0, 8);
}
// Add padding to leaf, otherwise i get "invalid indirect read from stack off -8+6 size 8"
for (;p<29;) {
leaf->p[p++] = '\0';
}
}
}
}
return 0;
}
```
I really appreciate any help you can provide.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.