/*
 * ip-address.c
 * This file is part of Network-inador
 *
 * Copyright (C) 2019, 2020 - Félix Arreola Rodríguez
 *
 * Network-inador is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Network-inador is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Network-inador; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 */

#ifndef __IP_ADDRESS_H__
#define __IP_ADDRESS_H__

#include <netlink/socket.h>
#include <netlink/msg.h>

#include "network-inador-private.h"

#include "interfaces.h"
#include "struct_addr_union.h"

#ifndef INFINITY_LIFE_TIME
#define     INFINITY_LIFE_TIME      0xFFFFFFFFU
#endif

typedef struct _IPAddr {
	sa_family_t family;
	
	uint8_t prefix;
	struct_addr local_addr;
	struct_addr addr;
	struct_addr brd_addr;
	
	char label[256];
	struct ifa_cacheinfo cacheinfo;
	
	uint8_t is_p2p;
	uint8_t has_brd;
	uint8_t has_local;
	
	uint32_t flags;
	uint8_t scope;
	
	Interface *iface;
} IPAddr;

int ip_address_receive_message_newaddr (struct nl_msg *msg, void *arg);
int ip_address_receive_message_deladdr (struct nl_msg *msg, void *arg);
void ip_address_init (NetworkInadorHandle *handle);

int ip_address_add_ip (NetworkInadorHandle *handle, int index, uint8_t ip_family, uint8_t ip_prefix, uint8_t ip_has_local, uint8_t ip_has_brd, uint8_t ip_scope, uint32_t ip_flags, struct ifa_cacheinfo *ip_cacheinfo, void *ip_addr, void *ip_local_addr, void *ip_brd_addr);
int ip_address_del_ip (NetworkInadorHandle *handle, int index, uint8_t ip_family, uint8_t ip_prefix, uint8_t ip_has_local, void *ip_addr, void *ip_local_addr);

IPAddr *_ip_address_search_addr (Interface *iface, sa_family_t family, void *addr, uint32_t prefix, void *local_addr);

#endif