199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation. 399a2dd95SBruce Richardson * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org> 499a2dd95SBruce Richardson * All rights reserved. 599a2dd95SBruce Richardson */ 699a2dd95SBruce Richardson 799a2dd95SBruce Richardson #ifndef _PARSE_IPADDR_H_ 899a2dd95SBruce Richardson #define _PARSE_IPADDR_H_ 999a2dd95SBruce Richardson 1099a2dd95SBruce Richardson #include <cmdline_parse.h> 1199a2dd95SBruce Richardson #include <rte_ip.h> 1299a2dd95SBruce Richardson 1399a2dd95SBruce Richardson #ifdef __cplusplus 1499a2dd95SBruce Richardson extern "C" { 1599a2dd95SBruce Richardson #endif 1699a2dd95SBruce Richardson 1799a2dd95SBruce Richardson #define CMDLINE_IPADDR_V4 0x01 1899a2dd95SBruce Richardson #define CMDLINE_IPADDR_V6 0x02 1999a2dd95SBruce Richardson #define CMDLINE_IPADDR_NETWORK 0x04 2099a2dd95SBruce Richardson 2199a2dd95SBruce Richardson struct cmdline_ipaddr { 2299a2dd95SBruce Richardson uint8_t family; 2399a2dd95SBruce Richardson union { 2499a2dd95SBruce Richardson struct in_addr ipv4; 25*52e04a63SRobin Jarry struct rte_ipv6_addr ipv6; 2699a2dd95SBruce Richardson } addr; 2799a2dd95SBruce Richardson unsigned int prefixlen; /* in case of network only */ 2899a2dd95SBruce Richardson }; 2999a2dd95SBruce Richardson typedef struct cmdline_ipaddr cmdline_ipaddr_t; 3099a2dd95SBruce Richardson 3199a2dd95SBruce Richardson struct cmdline_token_ipaddr_data { 3299a2dd95SBruce Richardson uint8_t flags; 3399a2dd95SBruce Richardson }; 3499a2dd95SBruce Richardson 3599a2dd95SBruce Richardson struct cmdline_token_ipaddr { 3699a2dd95SBruce Richardson struct cmdline_token_hdr hdr; 3799a2dd95SBruce Richardson struct cmdline_token_ipaddr_data ipaddr_data; 3899a2dd95SBruce Richardson }; 3999a2dd95SBruce Richardson typedef struct cmdline_token_ipaddr cmdline_parse_token_ipaddr_t; 4099a2dd95SBruce Richardson 4199a2dd95SBruce Richardson extern struct cmdline_token_ops cmdline_token_ipaddr_ops; 4299a2dd95SBruce Richardson 4399a2dd95SBruce Richardson int cmdline_parse_ipaddr(cmdline_parse_token_hdr_t *tk, const char *srcbuf, 4499a2dd95SBruce Richardson void *res, unsigned ressize); 4599a2dd95SBruce Richardson int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, 4699a2dd95SBruce Richardson unsigned int size); 4799a2dd95SBruce Richardson 4899a2dd95SBruce Richardson #define TOKEN_IPADDR_INITIALIZER(structure, field) \ 4999a2dd95SBruce Richardson { \ 5099a2dd95SBruce Richardson /* hdr */ \ 5199a2dd95SBruce Richardson { \ 5299a2dd95SBruce Richardson &cmdline_token_ipaddr_ops, /* ops */ \ 5399a2dd95SBruce Richardson offsetof(structure, field), /* offset */ \ 5499a2dd95SBruce Richardson }, \ 5599a2dd95SBruce Richardson /* ipaddr_data */ \ 5699a2dd95SBruce Richardson { \ 5799a2dd95SBruce Richardson CMDLINE_IPADDR_V4 | /* flags */ \ 5899a2dd95SBruce Richardson CMDLINE_IPADDR_V6, \ 5999a2dd95SBruce Richardson }, \ 6099a2dd95SBruce Richardson } 6199a2dd95SBruce Richardson 6299a2dd95SBruce Richardson #define TOKEN_IPV4_INITIALIZER(structure, field) \ 6399a2dd95SBruce Richardson { \ 6499a2dd95SBruce Richardson /* hdr */ \ 6599a2dd95SBruce Richardson { \ 6699a2dd95SBruce Richardson &cmdline_token_ipaddr_ops, /* ops */ \ 6799a2dd95SBruce Richardson offsetof(structure, field), /* offset */ \ 6899a2dd95SBruce Richardson }, \ 6999a2dd95SBruce Richardson /* ipaddr_data */ \ 7099a2dd95SBruce Richardson { \ 7199a2dd95SBruce Richardson CMDLINE_IPADDR_V4, /* flags */ \ 7299a2dd95SBruce Richardson }, \ 7399a2dd95SBruce Richardson } 7499a2dd95SBruce Richardson 7599a2dd95SBruce Richardson #define TOKEN_IPV6_INITIALIZER(structure, field) \ 7699a2dd95SBruce Richardson { \ 7799a2dd95SBruce Richardson /* hdr */ \ 7899a2dd95SBruce Richardson { \ 7999a2dd95SBruce Richardson &cmdline_token_ipaddr_ops, /* ops */ \ 8099a2dd95SBruce Richardson offsetof(structure, field), /* offset */ \ 8199a2dd95SBruce Richardson }, \ 8299a2dd95SBruce Richardson /* ipaddr_data */ \ 8399a2dd95SBruce Richardson { \ 8499a2dd95SBruce Richardson CMDLINE_IPADDR_V6, /* flags */ \ 8599a2dd95SBruce Richardson }, \ 8699a2dd95SBruce Richardson } 8799a2dd95SBruce Richardson 8899a2dd95SBruce Richardson #define TOKEN_IPNET_INITIALIZER(structure, field) \ 8999a2dd95SBruce Richardson { \ 9099a2dd95SBruce Richardson /* hdr */ \ 9199a2dd95SBruce Richardson { \ 9299a2dd95SBruce Richardson &cmdline_token_ipaddr_ops, /* ops */ \ 9399a2dd95SBruce Richardson offsetof(structure, field), /* offset */ \ 9499a2dd95SBruce Richardson }, \ 9599a2dd95SBruce Richardson /* ipaddr_data */ \ 9699a2dd95SBruce Richardson { \ 9799a2dd95SBruce Richardson CMDLINE_IPADDR_V4 | /* flags */ \ 9899a2dd95SBruce Richardson CMDLINE_IPADDR_V6 | \ 9999a2dd95SBruce Richardson CMDLINE_IPADDR_NETWORK, \ 10099a2dd95SBruce Richardson }, \ 10199a2dd95SBruce Richardson } 10299a2dd95SBruce Richardson 10399a2dd95SBruce Richardson #define TOKEN_IPV4NET_INITIALIZER(structure, field) \ 10499a2dd95SBruce Richardson { \ 10599a2dd95SBruce Richardson /* hdr */ \ 10699a2dd95SBruce Richardson { \ 10799a2dd95SBruce Richardson &cmdline_token_ipaddr_ops, /* ops */ \ 10899a2dd95SBruce Richardson offsetof(structure, field), /* offset */ \ 10999a2dd95SBruce Richardson }, \ 11099a2dd95SBruce Richardson /* ipaddr_data */ \ 11199a2dd95SBruce Richardson { \ 11299a2dd95SBruce Richardson CMDLINE_IPADDR_V4 | /* flags */ \ 11399a2dd95SBruce Richardson CMDLINE_IPADDR_NETWORK, \ 11499a2dd95SBruce Richardson }, \ 11599a2dd95SBruce Richardson } 11699a2dd95SBruce Richardson 11799a2dd95SBruce Richardson #define TOKEN_IPV6NET_INITIALIZER(structure, field) \ 11899a2dd95SBruce Richardson { \ 11999a2dd95SBruce Richardson /* hdr */ \ 12099a2dd95SBruce Richardson { \ 12199a2dd95SBruce Richardson &cmdline_token_ipaddr_ops, /* ops */ \ 12299a2dd95SBruce Richardson offsetof(structure, field), /* offset */ \ 12399a2dd95SBruce Richardson }, \ 12499a2dd95SBruce Richardson /* ipaddr_data */ \ 12599a2dd95SBruce Richardson { \ 12699a2dd95SBruce Richardson CMDLINE_IPADDR_V4 | /* flags */ \ 12799a2dd95SBruce Richardson CMDLINE_IPADDR_NETWORK, \ 12899a2dd95SBruce Richardson }, \ 12999a2dd95SBruce Richardson } 13099a2dd95SBruce Richardson 13199a2dd95SBruce Richardson #ifdef __cplusplus 13299a2dd95SBruce Richardson } 13399a2dd95SBruce Richardson #endif 13499a2dd95SBruce Richardson 13599a2dd95SBruce Richardson #endif /* _PARSE_IPADDR_H_ */ 136