1/** 2 * \file 3 * \brief Port allocator for netd 4 * 5 * This file is part of the net "daemon" 6 */ 7 8/* 9 * Copyright (c) 2007, 2008, 2009, 2010 ETH Zurich. 10 * All rights reserved. 11 * 12 * This file is distributed under the terms in the attached LICENSE file. 13 * If you do not find this file, copies can be found by writing to: 14 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: NetOS Group. 15 */ 16 17#ifndef _PORTALLOC_H_ 18#define _PORTALLOC_H_ 19 20#include <stdlib.h> 21#include <barrelfish/barrelfish.h> 22#include <if/net_ports_defs.h> 23 24/***************************************************************************** 25 * Constants 26 ****************************************************************************/ 27 28#define TCP_LOCAL_PORT_RANGE_START 8192 29#define TCP_LOCAL_PORT_RANGE_END 0x7fff 30#define TCP_ARRAY_SIZE (((TCP_LOCAL_PORT_RANGE_END - \ 31 0 + 1) / \ 32 sizeof(uint64_t)) + \ 33 (((TCP_LOCAL_PORT_RANGE_END - \ 34 0 + 1) % \ 35 sizeof(uint64_t)) != 0) \ 36 ) 37 38#define UDP_LOCAL_PORT_RANGE_START 8192 39#define UDP_LOCAL_PORT_RANGE_END 0x7fff 40#define UDP_ARRAY_SIZE (((UDP_LOCAL_PORT_RANGE_END - \ 41 0 + 1) / \ 42 sizeof(uint64_t)) + \ 43 (((UDP_LOCAL_PORT_RANGE_END - \ 44 0 + 1) % \ 45 sizeof(uint64_t)) != 0) \ 46 ) 47 48//#define M64 ((1L << 64) - 1) // XXX 49#define M64 0xffffffffffffffff 50#define M32 0xffffffff 51 52/***************************************************************************** 53 * Prototypes 54 ****************************************************************************/ 55 56void init_free_ports(void); 57 58uint16_t alloc_tcp_port(void); 59uint16_t alloc_udp_port(void); 60 61uint16_t alloc_specific_port(uint16_t port, net_ports_port_type_t type); 62void free_port(uint16_t port, net_ports_port_type_t type); 63 64#endif 65