// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/linux/route.c
// Function: add_del_interface_rules
int add_del_interface_rules(int8_t rule_action)
{
	int32_t tmp_fd;
	uint32_t addr, netaddr;
	int len;
	uint8_t netmask, if_count = 1;
	char *buf, *buf_ptr;
	struct ifconf ifc;
	struct ifreq *ifr, ifr_tmp;
	struct batman_if *batman_if;


	tmp_fd = socket(AF_INET, SOCK_DGRAM, 0);

	if (tmp_fd < 0) {
		debug_output(0, "Error - can't %s interface rules (udp socket): %s\n", (rule_action == RULE_DEL ? "delete" : "add"), strerror(errno));
		return -1;
	}


	len = 10 * sizeof(struct ifreq); /* initial buffer size guess (10 interfaces) */

	while (1) {

		buf = debugMalloc(len, 601);
		ifc.ifc_len = len;
		ifc.ifc_buf = buf;

		if (ioctl(tmp_fd, SIOCGIFCONF, &ifc) < 0) {

			debug_output(0, "Error - can't %s interface rules (SIOCGIFCONF): %s\n", (rule_action == RULE_DEL ? "delete" : "add"), strerror(errno));
			close(tmp_fd);
			debugFree(buf, 1606);
			return -1;

		} else {

			if (ifc.ifc_len < len)
				break;

		}

		len += 10 * sizeof(struct ifreq);
		debugFree(buf, 1601);

	}

	for (buf_ptr = buf; buf_ptr < buf + ifc.ifc_len;) {

		ifr = (struct ifreq *)buf_ptr;
		buf_ptr += (ifr->ifr_addr.sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr)) + sizeof(ifr->ifr_name);

		/* ignore if not IPv4 interface */
		if (ifr->ifr_addr.sa_family != AF_INET)
			continue;

		/* the tunnel thread will remove the default route by itself */
		if (strncmp(ifr->ifr_name, "gate", 4) == 0)
			continue;

		memset(&ifr_tmp, 0, sizeof (struct ifreq));
		strncpy(ifr_tmp.ifr_name, ifr->ifr_name, IFNAMSIZ - 1);

		if (ioctl(tmp_fd, SIOCGIFFLAGS, &ifr_tmp ) < 0) {

			debug_output(0, "Error - can't get flags of interface %s (interface rules): %s\n", ifr->ifr_name, strerror(errno));
			continue;

		}

		/* ignore if not up and running */
		if (!( ifr_tmp.ifr_flags & IFF_UP) || !(ifr_tmp.ifr_flags & IFF_RUNNING))
			continue;


		if (ioctl(tmp_fd, SIOCGIFADDR, &ifr_tmp) < 0) {

			debug_output(0, "Error - can't get IP address of interface %s (interface rules): %s\n", ifr->ifr_name, strerror(errno));
			continue;

		}

		addr = ((struct sockaddr_in *)&ifr_tmp.ifr_addr)->sin_addr.s_addr;

		if (ioctl(tmp_fd, SIOCGIFNETMASK, &ifr_tmp) < 0) {

			debug_output(0, "Error - can't get netmask address of interface %s (interface rules): %s\n", ifr->ifr_name, strerror(errno));
			continue;

		}

		netaddr = (((struct sockaddr_in *)&ifr_tmp.ifr_addr)->sin_addr.s_addr & addr);
		netmask = bit_count(((struct sockaddr_in *)&ifr_tmp.ifr_addr)->sin_addr.s_addr);

		add_del_route(netaddr, netmask, 0, 0, 0, ifr->ifr_name, BATMAN_RT_TABLE_TUNNEL, ROUTE_TYPE_THROW, rule_action);

		if (is_batman_if(ifr->ifr_name, &batman_if))
			continue;

		add_del_rule(netaddr, netmask, BATMAN_RT_TABLE_TUNNEL, (rule_action == RULE_DEL ? 0 : BATMAN_RT_PRIO_TUNNEL + if_count), 0, RULE_TYPE_SRC, rule_action);

		if (strncmp( ifr->ifr_name, "lo", IFNAMSIZ - 1) == 0)
			add_del_rule(0, 0, BATMAN_RT_TABLE_TUNNEL, BATMAN_RT_PRIO_TUNNEL, "lo\0 ", RULE_TYPE_IIF, rule_action);

		if_count++;

	}

	close(tmp_fd);
	debugFree(buf, 1605);

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %dil, %al
movb %al, -0x5(%rbp)
movb $0x1, -0x1a(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x2500
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0xb368
movsbl -0x5(%rbp), %edx
leaq 0xab58(%rip), %rax      # 0x15e7f
leaq 0xace4(%rip), %rcx      # 0x16012
cmpl $0x1, %edx
cmoveq %rcx, %rax
movq %rax, -0x80(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x80(%rbp), %rdx
movq %rax, %rcx
xorl %edi, %edi
leaq 0xade0(%rip), %rsi      # 0x16135
movb $0x0, %al
callq 0x123f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb70b
movl $0x190, -0x18(%rbp)     # imm = 0x190
movl -0x18(%rbp), %edi
movl $0x259, %esi            # imm = 0x259
callq 0x7220
movq %rax, -0x28(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0xc(%rbp), %edi
movl $0x8912, %esi           # imm = 0x8912
leaq -0x40(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xb40e
movsbl -0x5(%rbp), %edx
leaq 0xaace(%rip), %rax      # 0x15e7f
leaq 0xac5a(%rip), %rcx      # 0x16012
cmpl $0x1, %edx
cmoveq %rcx, %rax
movq %rax, -0x88(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x88(%rbp), %rdx
movq %rax, %rcx
xorl %edi, %edi
leaq 0xad83(%rip), %rsi      # 0x16168
movb $0x0, %al
callq 0x123f0
movl -0xc(%rbp), %edi
callq 0x2210
movq -0x28(%rbp), %rdi
movl $0x646, %esi            # imm = 0x646
callq 0x7720
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb70b
movl -0x40(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xb418
jmp 0xb43a
jmp 0xb41a
movslq -0x18(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movl %eax, -0x18(%rbp)
movq -0x28(%rbp), %rdi
movl $0x641, %esi            # imm = 0x641
callq 0x7720
jmp 0xb36f
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0xb6ee
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzwl 0x10(%rax), %edx
movl $0x10, %eax
movl $0x1c, %ecx
cmpl $0xa, %edx
cmoveq %rcx, %rax
addq $0x10, %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x2, %eax
je 0xb496
jmp 0xb442
movq -0x48(%rbp), %rdi
leaq 0xacfb(%rip), %rsi      # 0x1619c
movl $0x4, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0xb4b2
jmp 0xb442
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x21e0
leaq -0x70(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0xf, %edx
callq 0x2090
movl -0xc(%rbp), %edi
movl $0x8913, %esi           # imm = 0x8913
leaq -0x70(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xb522
movq -0x48(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x90(%rbp), %rdx
movq %rax, %rcx
xorl %edi, %edi
leaq 0xac8b(%rip), %rsi      # 0x161a1
movb $0x0, %al
callq 0x123f0
jmp 0xb442
movswl -0x60(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xb53a
movswl -0x60(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0xb53f
jmp 0xb442
movl -0xc(%rbp), %edi
movl $0x8915, %esi           # imm = 0x8915
leaq -0x70(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xb58d
movq -0x48(%rbp), %rax
movq %rax, -0x98(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x98(%rbp), %rdx
movq %rax, %rcx
xorl %edi, %edi
leaq 0xac5f(%rip), %rsi      # 0x161e0
movb $0x0, %al
callq 0x123f0
jmp 0xb442
movl -0x5c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %edi
movl $0x891b, %esi           # imm = 0x891B
leaq -0x70(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xb5e1
movq -0x48(%rbp), %rax
movq %rax, -0xa0(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0xa0(%rbp), %rdx
movq %rax, %rcx
xorl %edi, %edi
leaq 0xac4f(%rip), %rsi      # 0x16224
movb $0x0, %al
callq 0x123f0
jmp 0xb442
movl -0x5c(%rbp), %eax
andl -0x10(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x5c(%rbp), %edi
callq 0x7e30
movb %al, -0x19(%rbp)
movl -0x14(%rbp), %edi
movb -0x19(%rbp), %al
movq -0x48(%rbp), %r9
xorl %r8d, %r8d
movzbl %al, %esi
movl %r8d, %edx
movl %r8d, %ecx
movl $0x44, (%rsp)
movl $0x1, 0x8(%rsp)
movsbl -0x5(%rbp), %eax
movl %eax, 0x10(%rsp)
callq 0xa420
movq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2bf0
cmpl $0x0, %eax
je 0xb63e
jmp 0xb442
movl -0x14(%rbp), %eax
movl %eax, -0xa8(%rbp)
movb -0x19(%rbp), %al
movb %al, -0xa1(%rbp)
movsbl -0x5(%rbp), %eax
cmpl $0x1, %eax
jne 0xb663
xorl %eax, %eax
movl %eax, -0xac(%rbp)
jmp 0xb672
movzbl -0x1a(%rbp), %eax
addl $0x1a90, %eax           # imm = 0x1A90
movl %eax, -0xac(%rbp)
movb -0xa1(%rbp), %al
movl -0xa8(%rbp), %edi
movl -0xac(%rbp), %ecx
movl $0x44, %edx
xorl %esi, %esi
movl %esi, %r8d
xorl %r9d, %r9d
movzbl %al, %esi
movsbl -0x5(%rbp), %eax
movl %eax, (%rsp)
callq 0xacd0
movq -0x48(%rbp), %rdi
leaq 0xabc2(%rip), %rsi      # 0x1626d
movl $0xf, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0xb6e1
xorl %esi, %esi
movl $0x44, %edx
movl $0x1a90, %ecx           # imm = 0x1A90
leaq 0xa787(%rip), %r8       # 0x15e54
movl $0x2, %r9d
movl %esi, %edi
movsbl -0x5(%rbp), %eax
movl %eax, (%rsp)
callq 0xacd0
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0xb442
movl -0xc(%rbp), %edi
callq 0x2210
movq -0x28(%rbp), %rdi
movl $0x645, %esi            # imm = 0x645
callq 0x7720
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)