2006-08-08 17:07:07 +04:00
|
|
|
/*
|
2008-02-28 18:43:27 +03:00
|
|
|
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
|
2006-08-08 17:07:07 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef NET_DATALINK_H
|
|
|
|
#define NET_DATALINK_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <net_buffer.h>
|
|
|
|
#include <net_routing_info.h>
|
|
|
|
|
|
|
|
#include <util/list.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define NET_DATALINK_MODULE_NAME "network/stack/datalink/v1"
|
|
|
|
|
|
|
|
typedef struct net_datalink_protocol net_datalink_protocol;
|
|
|
|
|
|
|
|
typedef struct net_domain {
|
|
|
|
const char *name;
|
|
|
|
int family;
|
|
|
|
struct list interfaces;
|
|
|
|
|
|
|
|
struct net_protocol_module_info *module;
|
|
|
|
struct net_address_module_info *address_module;
|
|
|
|
} net_domain;
|
|
|
|
|
|
|
|
struct net_interface {
|
|
|
|
struct list_link link;
|
|
|
|
struct net_domain *domain;
|
|
|
|
struct net_device *device;
|
|
|
|
struct net_datalink_protocol *first_protocol;
|
|
|
|
struct net_datalink_protocol_module_info *first_info;
|
|
|
|
|
|
|
|
char name[IF_NAMESIZE];
|
|
|
|
struct sockaddr *address;
|
|
|
|
struct sockaddr *destination;
|
|
|
|
struct sockaddr *mask;
|
|
|
|
uint32 index;
|
|
|
|
uint32 flags;
|
|
|
|
uint8 type;
|
|
|
|
uint32 mtu;
|
|
|
|
uint32 metric;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct net_route {
|
|
|
|
struct sockaddr *destination;
|
|
|
|
struct sockaddr *mask;
|
|
|
|
struct sockaddr *gateway;
|
|
|
|
uint32 flags;
|
|
|
|
uint32 mtu;
|
|
|
|
struct net_interface *interface;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct net_route_info {
|
|
|
|
struct list_link link;
|
|
|
|
struct net_route *route;
|
|
|
|
struct sockaddr address;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct net_datalink_module_info {
|
|
|
|
module_info info;
|
|
|
|
|
|
|
|
status_t (*control)(struct net_domain *domain, int32 option, void *value,
|
|
|
|
size_t *_length);
|
|
|
|
status_t (*send_data)(struct net_route *route, struct net_buffer *buffer);
|
2007-04-16 02:11:12 +04:00
|
|
|
status_t (*send_datagram)(struct net_protocol *protocol,
|
2008-02-28 18:43:27 +03:00
|
|
|
struct net_domain *domain, struct net_buffer *buffer);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2007-04-16 02:11:12 +04:00
|
|
|
bool (*is_local_address)(struct net_domain *domain,
|
2009-12-03 17:31:39 +03:00
|
|
|
const struct sockaddr *address, net_interface **_interface,
|
2006-12-06 21:38:38 +03:00
|
|
|
uint32 *_matchedType);
|
2009-12-03 17:31:39 +03:00
|
|
|
bool (*is_local_link_address)(struct net_domain *domain, bool unconfigured,
|
|
|
|
const struct sockaddr *address, net_interface **_interface);
|
2010-04-12 23:06:46 +04:00
|
|
|
|
2007-04-15 07:07:28 +04:00
|
|
|
net_interface *(*get_interface)(struct net_domain *domain, uint32 index);
|
2007-04-15 06:44:01 +04:00
|
|
|
net_interface *(*get_interface_with_address)(struct net_domain *domain,
|
2008-02-28 18:43:27 +03:00
|
|
|
const struct sockaddr *address);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
// routes
|
|
|
|
status_t (*add_route)(struct net_domain *domain,
|
|
|
|
const struct net_route *route);
|
|
|
|
status_t (*remove_route)(struct net_domain *domain,
|
|
|
|
const struct net_route *route);
|
|
|
|
struct net_route *(*get_route)(struct net_domain *domain,
|
|
|
|
const struct sockaddr *address);
|
2007-04-12 02:24:12 +04:00
|
|
|
status_t (*get_buffer_route)(struct net_domain *domain,
|
2008-02-28 18:43:27 +03:00
|
|
|
struct net_buffer *buffer, struct net_route **_route);
|
2006-08-08 17:07:07 +04:00
|
|
|
void (*put_route)(struct net_domain *domain, struct net_route *route);
|
|
|
|
|
|
|
|
status_t (*register_route_info)(struct net_domain *domain,
|
|
|
|
struct net_route_info *info);
|
|
|
|
status_t (*unregister_route_info)(struct net_domain *domain,
|
|
|
|
struct net_route_info *info);
|
|
|
|
status_t (*update_route_info)(struct net_domain *domain,
|
|
|
|
struct net_route_info *info);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct net_address_module_info {
|
|
|
|
module_info info;
|
|
|
|
|
|
|
|
status_t (*copy_address)(const sockaddr *from, sockaddr **to,
|
2008-02-28 18:43:27 +03:00
|
|
|
bool replaceWithZeros, const sockaddr *mask);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-04-12 23:06:46 +04:00
|
|
|
status_t (*mask_address)(const sockaddr *address, const sockaddr *mask,
|
2006-08-08 17:07:07 +04:00
|
|
|
sockaddr *result);
|
2010-04-12 23:06:46 +04:00
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
bool (*equal_addresses)(const sockaddr *a, const sockaddr *b);
|
|
|
|
bool (*equal_ports)(const sockaddr *a, const sockaddr *b);
|
|
|
|
bool (*equal_addresses_and_ports)(const sockaddr *a, const sockaddr *b);
|
2010-04-12 23:06:46 +04:00
|
|
|
bool (*equal_masked_addresses)(const sockaddr *a, const sockaddr *b,
|
2006-08-08 17:07:07 +04:00
|
|
|
const sockaddr *mask);
|
2008-02-28 18:43:27 +03:00
|
|
|
bool (*is_empty_address)(const sockaddr *address, bool checkPort);
|
2010-04-12 22:39:34 +04:00
|
|
|
bool (*is_same_family)(const sockaddr *address);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2006-09-17 21:34:22 +04:00
|
|
|
int32 (*first_mask_bit)(const sockaddr *mask);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2006-09-17 21:34:22 +04:00
|
|
|
bool (*check_mask)(const sockaddr *address);
|
2010-04-12 23:06:46 +04:00
|
|
|
|
|
|
|
status_t (*print_address)(const sockaddr *address, char **buffer,
|
2006-08-08 17:07:07 +04:00
|
|
|
bool printPort);
|
2007-04-29 23:03:06 +04:00
|
|
|
status_t (*print_address_buffer)(const sockaddr *address, char *buffer,
|
|
|
|
size_t bufferSize, bool printPort);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
uint16 (*get_port)(const sockaddr *address);
|
|
|
|
status_t (*set_port)(sockaddr *address, uint16 port);
|
|
|
|
|
|
|
|
status_t (*set_to)(sockaddr *address, const sockaddr *from);
|
|
|
|
status_t (*set_to_empty_address)(sockaddr *address);
|
2008-02-28 18:43:27 +03:00
|
|
|
status_t (*set_to_defaults)(sockaddr *defaultMask,
|
|
|
|
sockaddr *defaultBroadcast, sockaddr *address,
|
|
|
|
sockaddr *netmask);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2007-04-12 02:24:12 +04:00
|
|
|
status_t (*update_to)(sockaddr *address, const sockaddr *from);
|
|
|
|
|
2010-04-12 23:06:46 +04:00
|
|
|
uint32 (*hash_address_pair)(const sockaddr *ourAddress,
|
2006-08-08 17:07:07 +04:00
|
|
|
const sockaddr *peerAddress);
|
|
|
|
|
2010-04-12 23:06:46 +04:00
|
|
|
status_t (*checksum_address)(struct Checksum *checksum,
|
2006-08-08 17:07:07 +04:00
|
|
|
const sockaddr *address);
|
|
|
|
|
2010-04-12 22:39:34 +04:00
|
|
|
void (*get_loopback_address)(sockaddr *result);
|
2006-08-08 17:07:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NET_DATALINK_H
|