18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky * Copyright (c) 2010 Panasas, Inc.
58d59ecb2SHans Petter Selasky * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky * All rights reserved.
78d59ecb2SHans Petter Selasky *
88d59ecb2SHans Petter Selasky * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky * are met:
118d59ecb2SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky * notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky * disclaimer.
148d59ecb2SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky * documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky *
188d59ecb2SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky */
29*307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_NET_IP_H_
30*307f78f3SVladimir Kondratyev #define _LINUXKPI_NET_IP_H_
318d59ecb2SHans Petter Selasky
328d59ecb2SHans Petter Selasky #include "opt_inet.h"
338d59ecb2SHans Petter Selasky
348d59ecb2SHans Petter Selasky #include <sys/types.h>
358d59ecb2SHans Petter Selasky #include <sys/socket.h>
368d59ecb2SHans Petter Selasky
378d59ecb2SHans Petter Selasky #include <net/if_types.h>
388d59ecb2SHans Petter Selasky #include <net/if.h>
398d59ecb2SHans Petter Selasky #include <net/if_var.h>
408d59ecb2SHans Petter Selasky
418d59ecb2SHans Petter Selasky #include <netinet/in.h>
428d59ecb2SHans Petter Selasky #include <netinet/in_pcb.h>
438d59ecb2SHans Petter Selasky
4482d01407SHans Petter Selasky static inline void
inet_get_local_port_range(struct vnet * vnet,int * low,int * high)4582d01407SHans Petter Selasky inet_get_local_port_range(struct vnet *vnet, int *low, int *high)
468d59ecb2SHans Petter Selasky {
478d59ecb2SHans Petter Selasky #ifdef INET
4882d01407SHans Petter Selasky CURVNET_SET_QUIET(vnet);
498d59ecb2SHans Petter Selasky *low = V_ipport_firstauto;
508d59ecb2SHans Petter Selasky *high = V_ipport_lastauto;
518d59ecb2SHans Petter Selasky CURVNET_RESTORE();
528d59ecb2SHans Petter Selasky #else
538d59ecb2SHans Petter Selasky *low = IPPORT_EPHEMERALFIRST; /* 10000 */
548d59ecb2SHans Petter Selasky *high = IPPORT_EPHEMERALLAST; /* 65535 */
558d59ecb2SHans Petter Selasky #endif
568d59ecb2SHans Petter Selasky }
578d59ecb2SHans Petter Selasky
588d59ecb2SHans Petter Selasky static inline void
ip_eth_mc_map(uint32_t addr,char * buf)59986e3bedSHans Petter Selasky ip_eth_mc_map(uint32_t addr, char *buf)
60986e3bedSHans Petter Selasky {
61986e3bedSHans Petter Selasky
62986e3bedSHans Petter Selasky addr = ntohl(addr);
63986e3bedSHans Petter Selasky
64986e3bedSHans Petter Selasky buf[0] = 0x01;
65986e3bedSHans Petter Selasky buf[1] = 0x00;
66986e3bedSHans Petter Selasky buf[2] = 0x5e;
67986e3bedSHans Petter Selasky buf[3] = (addr >> 16) & 0x7f;
68986e3bedSHans Petter Selasky buf[4] = (addr >> 8) & 0xff;
69986e3bedSHans Petter Selasky buf[5] = (addr & 0xff);
70986e3bedSHans Petter Selasky }
71986e3bedSHans Petter Selasky
72986e3bedSHans Petter Selasky static inline void
ip_ib_mc_map(uint32_t addr,const unsigned char * bcast,char * buf)738d59ecb2SHans Petter Selasky ip_ib_mc_map(uint32_t addr, const unsigned char *bcast, char *buf)
748d59ecb2SHans Petter Selasky {
758d59ecb2SHans Petter Selasky unsigned char scope;
768d59ecb2SHans Petter Selasky
778d59ecb2SHans Petter Selasky addr = ntohl(addr);
788d59ecb2SHans Petter Selasky scope = bcast[5] & 0xF;
798d59ecb2SHans Petter Selasky buf[0] = 0;
808d59ecb2SHans Petter Selasky buf[1] = 0xff;
818d59ecb2SHans Petter Selasky buf[2] = 0xff;
828d59ecb2SHans Petter Selasky buf[3] = 0xff;
838d59ecb2SHans Petter Selasky buf[4] = 0xff;
848d59ecb2SHans Petter Selasky buf[5] = 0x10 | scope;
858d59ecb2SHans Petter Selasky buf[6] = 0x40;
868d59ecb2SHans Petter Selasky buf[7] = 0x1b;
878d59ecb2SHans Petter Selasky buf[8] = bcast[8];
888d59ecb2SHans Petter Selasky buf[9] = bcast[9];
898d59ecb2SHans Petter Selasky buf[10] = 0;
908d59ecb2SHans Petter Selasky buf[11] = 0;
918d59ecb2SHans Petter Selasky buf[12] = 0;
928d59ecb2SHans Petter Selasky buf[13] = 0;
938d59ecb2SHans Petter Selasky buf[14] = 0;
948d59ecb2SHans Petter Selasky buf[15] = 0;
958d59ecb2SHans Petter Selasky buf[16] = (addr >> 24) & 0xff;
968d59ecb2SHans Petter Selasky buf[17] = (addr >> 16) & 0xff;
978d59ecb2SHans Petter Selasky buf[18] = (addr >> 8) & 0xff;
988d59ecb2SHans Petter Selasky buf[19] = addr & 0xff;
998d59ecb2SHans Petter Selasky }
1008d59ecb2SHans Petter Selasky
101*307f78f3SVladimir Kondratyev #endif /* _LINUXKPI_NET_IP_H_ */
102