[02/12] net: add function to pretty print IPv4

Message ID 20211214141242.3383831-3-ronan.randles@intel.com (mailing list archive)
State Not Applicable, archived
Delegated to: Thomas Monjalon
Headers
Series add packet generator library and example app |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ronan Randles Dec. 14, 2021, 2:12 p.m. UTC
  This function accepts an uint32_t representation of an IP address and
produces a string representation stored in a char * buffer. Realavent
unit tests also included.

Signed-off-by: Ronan Randles <ronan.randles@intel.com>
---
 app/test/test_net.c | 26 ++++++++++++++++++++++++++
 lib/net/rte_ip.c    | 15 +++++++++++++++
 lib/net/rte_ip.h    | 20 ++++++++++++++++++++
 lib/net/version.map |  1 +
 4 files changed, 62 insertions(+)
  

Comments

Stephen Hemminger Dec. 14, 2021, 4:08 p.m. UTC | #1
On Tue, 14 Dec 2021 14:12:32 +0000
Ronan Randles <ronan.randles@intel.com> wrote:

> This function accepts an uint32_t representation of an IP address and
> produces a string representation stored in a char * buffer. Realavent
> unit tests also included.
> 
> Signed-off-by: Ronan Randles <ronan.randles@intel.com>

Do we really have to reinvent getnameinfo()?
Is this for Windows?
  
Morten Brørup Dec. 14, 2021, 5:31 p.m. UTC | #2
> From: Ronan Randles [mailto:ronan.randles@intel.com]
> Sent: Tuesday, 14 December 2021 15.13
> 
> This function accepts an uint32_t representation of an IP address and
> produces a string representation stored in a char * buffer. Realavent
> unit tests also included.
> 
> Signed-off-by: Ronan Randles <ronan.randles@intel.com>

[snip]

> diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> index 188054fda4..e46f0b41ba 100644
> --- a/lib/net/rte_ip.h
> +++ b/lib/net/rte_ip.h
> @@ -444,6 +444,26 @@ __rte_experimental
>  int32_t
>  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
> 
> +
> +/**
> + * Print IP address from 32 bit int into char * buffer.
> + *
> + * @param ip_addr
> + *   ip address to be printed.
> + * @param buffer
> + *   The buffer the string will be saved into.
> + * @param buffer_size
> + *   size of buffer to be used.
> + *
> + * @retval 0
> + *   Success.
> + * @retval -1
> + *   Failure due to invalid input arguments.
> + */
> +__rte_experimental
> +int32_t
> +rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t
> buffer_size);
> +

In continuation of my email reply about the IPv4 parse function...

I have a few suggestions to the IPv4 print function too:

The return value should be the number of characters written to the output string, and still -1 on error. With this modification, you could use the return type ssize_t instead of int32_t.

Furthermore, I would prefer having the parameters in the same order as snprintf(): char *str, size_t size, const uint32_t ip_addr. Please also notice the suggested changed type for the size, and the const added to the ip_addr.

-Morten
  
Morten Brørup Dec. 14, 2021, 5:42 p.m. UTC | #3
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Tuesday, 14 December 2021 17.09
> 
> On Tue, 14 Dec 2021 14:12:32 +0000
> Ronan Randles <ronan.randles@intel.com> wrote:
> 
> > This function accepts an uint32_t representation of an IP address and
> > produces a string representation stored in a char * buffer. Realavent
> > unit tests also included.
> >
> > Signed-off-by: Ronan Randles <ronan.randles@intel.com>
> 
> Do we really have to reinvent getnameinfo()?
> Is this for Windows?

For general inspiration:

We have an in-house to/from string library, where our xx_to_str() functions return char * and can take a NULL pointer as the buffer parameter to make it use a buffer from an small cyclic pool of string buffers in the library.

Probably not good from an academic standpoint, and not good for a generic library, but we know how many of these strings are being used simultaneously in our applications, so the pool is not overrun in reality. And it makes the code using these functions much shorter and readable.

-Morten
  
Ananyev, Konstantin Dec. 15, 2021, 1:06 a.m. UTC | #4
> -----Original Message-----
> From: Morten Brørup <mb@smartsharesystems.com>
> Sent: Tuesday, December 14, 2021 5:31 PM
> To: Randles, Ronan <ronan.randles@intel.com>; dev@dpdk.org
> Cc: Van Haaren, Harry <harry.van.haaren@intel.com>
> Subject: RE: [PATCH 02/12] net: add function to pretty print IPv4
> 
> > From: Ronan Randles [mailto:ronan.randles@intel.com]
> > Sent: Tuesday, 14 December 2021 15.13
> >
> > This function accepts an uint32_t representation of an IP address and
> > produces a string representation stored in a char * buffer. Realavent
> > unit tests also included.
> >
> > Signed-off-by: Ronan Randles <ronan.randles@intel.com>
> 
> [snip]
> 
> > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> > index 188054fda4..e46f0b41ba 100644
> > --- a/lib/net/rte_ip.h
> > +++ b/lib/net/rte_ip.h
> > @@ -444,6 +444,26 @@ __rte_experimental
> >  int32_t
> >  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
> >
> > +
> > +/**
> > + * Print IP address from 32 bit int into char * buffer.
> > + *
> > + * @param ip_addr
> > + *   ip address to be printed.
> > + * @param buffer
> > + *   The buffer the string will be saved into.
> > + * @param buffer_size
> > + *   size of buffer to be used.
> > + *
> > + * @retval 0
> > + *   Success.
> > + * @retval -1
> > + *   Failure due to invalid input arguments.
> > + */
> > +__rte_experimental
> > +int32_t
> > +rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t
> > buffer_size);
> > +
> 
> In continuation of my email reply about the IPv4 parse function...
> 
> I have a few suggestions to the IPv4 print function too:
> 
> The return value should be the number of characters written to the output string, and still -1 on error. With this modification, you could
> use the return type ssize_t instead of int32_t.
> 
> Furthermore, I would prefer having the parameters in the same order as snprintf(): char *str, size_t size, const uint32_t ip_addr. Please
> also notice the suggested changed type for the size, and the const added to the ip_addr.
> 
Honestly, I don't understand why we need to introduce such functions
inside DPDK at all.
What's wrong with existing standard ones: inet_ntop() and inet_pton()?
  
Stephen Hemminger Dec. 15, 2021, 3:20 a.m. UTC | #5
On Wed, 15 Dec 2021 01:06:14 +0000
"Ananyev, Konstantin" <konstantin.ananyev@intel.com> wrote:

> > -----Original Message-----
> > From: Morten Brørup <mb@smartsharesystems.com>
> > Sent: Tuesday, December 14, 2021 5:31 PM
> > To: Randles, Ronan <ronan.randles@intel.com>; dev@dpdk.org
> > Cc: Van Haaren, Harry <harry.van.haaren@intel.com>
> > Subject: RE: [PATCH 02/12] net: add function to pretty print IPv4
> >   
> > > From: Ronan Randles [mailto:ronan.randles@intel.com]
> > > Sent: Tuesday, 14 December 2021 15.13
> > >
> > > This function accepts an uint32_t representation of an IP address and
> > > produces a string representation stored in a char * buffer. Realavent
> > > unit tests also included.
> > >
> > > Signed-off-by: Ronan Randles <ronan.randles@intel.com>  
> > 
> > [snip]
> >   
> > > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> > > index 188054fda4..e46f0b41ba 100644
> > > --- a/lib/net/rte_ip.h
> > > +++ b/lib/net/rte_ip.h
> > > @@ -444,6 +444,26 @@ __rte_experimental
> > >  int32_t
> > >  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
> > >
> > > +
> > > +/**
> > > + * Print IP address from 32 bit int into char * buffer.
> > > + *
> > > + * @param ip_addr
> > > + *   ip address to be printed.
> > > + * @param buffer
> > > + *   The buffer the string will be saved into.
> > > + * @param buffer_size
> > > + *   size of buffer to be used.
> > > + *
> > > + * @retval 0
> > > + *   Success.
> > > + * @retval -1
> > > + *   Failure due to invalid input arguments.
> > > + */
> > > +__rte_experimental
> > > +int32_t
> > > +rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t
> > > buffer_size);
> > > +  
> > 
> > In continuation of my email reply about the IPv4 parse function...
> > 
> > I have a few suggestions to the IPv4 print function too:
> > 
> > The return value should be the number of characters written to the output string, and still -1 on error. With this modification, you could
> > use the return type ssize_t instead of int32_t.
> > 
> > Furthermore, I would prefer having the parameters in the same order as snprintf(): char *str, size_t size, const uint32_t ip_addr. Please
> > also notice the suggested changed type for the size, and the const added to the ip_addr.
> >   
> Honestly, I don't understand why we need to introduce such functions
> inside DPDK at all.
> What's wrong with existing standard ones: inet_ntop() and inet_pton()?

Agreed, I see no added value in reinventing here
  
Morten Brørup Dec. 15, 2021, 7:23 a.m. UTC | #6
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Wednesday, 15 December 2021 04.21
> 
> On Wed, 15 Dec 2021 01:06:14 +0000
> "Ananyev, Konstantin" <konstantin.ananyev@intel.com> wrote:
> 
> > > -----Original Message-----
> > > From: Morten Brørup <mb@smartsharesystems.com>
> > > Sent: Tuesday, December 14, 2021 5:31 PM
> > > To: Randles, Ronan <ronan.randles@intel.com>; dev@dpdk.org
> > > Cc: Van Haaren, Harry <harry.van.haaren@intel.com>
> > > Subject: RE: [PATCH 02/12] net: add function to pretty print IPv4
> > >
> > > > From: Ronan Randles [mailto:ronan.randles@intel.com]
> > > > Sent: Tuesday, 14 December 2021 15.13
> > > >
> > > > This function accepts an uint32_t representation of an IP address
> and
> > > > produces a string representation stored in a char * buffer.
> Realavent
> > > > unit tests also included.
> > > >
> > > > Signed-off-by: Ronan Randles <ronan.randles@intel.com>
> > >
> > > [snip]
> > >
> > > > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> > > > index 188054fda4..e46f0b41ba 100644
> > > > --- a/lib/net/rte_ip.h
> > > > +++ b/lib/net/rte_ip.h
> > > > @@ -444,6 +444,26 @@ __rte_experimental
> > > >  int32_t
> > > >  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
> > > >
> > > > +
> > > > +/**
> > > > + * Print IP address from 32 bit int into char * buffer.
> > > > + *
> > > > + * @param ip_addr
> > > > + *   ip address to be printed.
> > > > + * @param buffer
> > > > + *   The buffer the string will be saved into.
> > > > + * @param buffer_size
> > > > + *   size of buffer to be used.
> > > > + *
> > > > + * @retval 0
> > > > + *   Success.
> > > > + * @retval -1
> > > > + *   Failure due to invalid input arguments.
> > > > + */
> > > > +__rte_experimental
> > > > +int32_t
> > > > +rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t
> > > > buffer_size);
> > > > +
> > >
> > > In continuation of my email reply about the IPv4 parse function...
> > >
> > > I have a few suggestions to the IPv4 print function too:
> > >
> > > The return value should be the number of characters written to the
> output string, and still -1 on error. With this modification, you could
> > > use the return type ssize_t instead of int32_t.
> > >
> > > Furthermore, I would prefer having the parameters in the same order
> as snprintf(): char *str, size_t size, const uint32_t ip_addr. Please
> > > also notice the suggested changed type for the size, and the const
> added to the ip_addr.
> > >
> > Honestly, I don't understand why we need to introduce such functions
> > inside DPDK at all.
> > What's wrong with existing standard ones: inet_ntop() and
> inet_pton()?
> 
> Agreed, I see no added value in reinventing here

I think that DPDK functions for converting all sorts of types to/from strings would be useful; not only IP addresses, but also MAC addresses, TCP/UDP port numbers and VLAN IDs.

If you don't like IP address string conversion functions in the net library, DPDK could have a string conversions library. That library could expose a multitude of APIs for the same purpose, so the application can use the API that best fits each application use.
  
Ananyev, Konstantin Dec. 15, 2021, 1:06 p.m. UTC | #7
> > From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> > Sent: Wednesday, 15 December 2021 04.21
> >
> > On Wed, 15 Dec 2021 01:06:14 +0000
> > "Ananyev, Konstantin" <konstantin.ananyev@intel.com> wrote:
> >
> > > > -----Original Message-----
> > > > From: Morten Brørup <mb@smartsharesystems.com>
> > > > Sent: Tuesday, December 14, 2021 5:31 PM
> > > > To: Randles, Ronan <ronan.randles@intel.com>; dev@dpdk.org
> > > > Cc: Van Haaren, Harry <harry.van.haaren@intel.com>
> > > > Subject: RE: [PATCH 02/12] net: add function to pretty print IPv4
> > > >
> > > > > From: Ronan Randles [mailto:ronan.randles@intel.com]
> > > > > Sent: Tuesday, 14 December 2021 15.13
> > > > >
> > > > > This function accepts an uint32_t representation of an IP address
> > and
> > > > > produces a string representation stored in a char * buffer.
> > Realavent
> > > > > unit tests also included.
> > > > >
> > > > > Signed-off-by: Ronan Randles <ronan.randles@intel.com>
> > > >
> > > > [snip]
> > > >
> > > > > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> > > > > index 188054fda4..e46f0b41ba 100644
> > > > > --- a/lib/net/rte_ip.h
> > > > > +++ b/lib/net/rte_ip.h
> > > > > @@ -444,6 +444,26 @@ __rte_experimental
> > > > >  int32_t
> > > > >  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
> > > > >
> > > > > +
> > > > > +/**
> > > > > + * Print IP address from 32 bit int into char * buffer.
> > > > > + *
> > > > > + * @param ip_addr
> > > > > + *   ip address to be printed.
> > > > > + * @param buffer
> > > > > + *   The buffer the string will be saved into.
> > > > > + * @param buffer_size
> > > > > + *   size of buffer to be used.
> > > > > + *
> > > > > + * @retval 0
> > > > > + *   Success.
> > > > > + * @retval -1
> > > > > + *   Failure due to invalid input arguments.
> > > > > + */
> > > > > +__rte_experimental
> > > > > +int32_t
> > > > > +rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t
> > > > > buffer_size);
> > > > > +
> > > >
> > > > In continuation of my email reply about the IPv4 parse function...
> > > >
> > > > I have a few suggestions to the IPv4 print function too:
> > > >
> > > > The return value should be the number of characters written to the
> > output string, and still -1 on error. With this modification, you could
> > > > use the return type ssize_t instead of int32_t.
> > > >
> > > > Furthermore, I would prefer having the parameters in the same order
> > as snprintf(): char *str, size_t size, const uint32_t ip_addr. Please
> > > > also notice the suggested changed type for the size, and the const
> > added to the ip_addr.
> > > >
> > > Honestly, I don't understand why we need to introduce such functions
> > > inside DPDK at all.
> > > What's wrong with existing standard ones: inet_ntop() and
> > inet_pton()?
> >
> > Agreed, I see no added value in reinventing here
> 
> I think that DPDK functions for converting all sorts of types to/from strings would be useful; not only IP addresses, but also MAC addresses,
> TCP/UDP port numbers and VLAN IDs.

For MACs we already have:
rte_ether_format_addr()/rte_ether_unformat_addr()

> 
> If you don't like IP address string conversion functions in the net library, DPDK could have a string conversions library. That library could
> expose a multitude of APIs for the same purpose, so the application can use the API that best fits each application use.

I don’t mind to add new functions into net lib, if they are useful ones.
But for that particular case, I just don't see what is the reason to
develop and maintain our own functions while existing analogues:
- are well known, widely adopted and field proven
- do provide the same or even more comprehensive functionality
  
Thomas Monjalon Jan. 19, 2022, 2:24 p.m. UTC | #8
15/12/2021 14:06, Ananyev, Konstantin:
> 
> > > From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> > > Sent: Wednesday, 15 December 2021 04.21
> > >
> > > On Wed, 15 Dec 2021 01:06:14 +0000
> > > "Ananyev, Konstantin" <konstantin.ananyev@intel.com> wrote:
> > > > > > --- a/lib/net/rte_ip.h
> > > > > > +++ b/lib/net/rte_ip.h
> > > > > > @@ -444,6 +444,26 @@ __rte_experimental
> > > > > >  int32_t
> > > > > >  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
> > > > > >
> > > > > > +
> > > > > > +/**
> > > > > > + * Print IP address from 32 bit int into char * buffer.
> > > > > > + *
> > > > > > + * @param ip_addr
> > > > > > + *   ip address to be printed.
> > > > > > + * @param buffer
> > > > > > + *   The buffer the string will be saved into.
> > > > > > + * @param buffer_size
> > > > > > + *   size of buffer to be used.
> > > > > > + *
> > > > > > + * @retval 0
> > > > > > + *   Success.
> > > > > > + * @retval -1
> > > > > > + *   Failure due to invalid input arguments.
> > > > > > + */
> > > > > > +__rte_experimental
> > > > > > +int32_t
> > > > > > +rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t
> > > > > > buffer_size);
> > > > > > +
> > > > >
> > > > > In continuation of my email reply about the IPv4 parse function...
> > > > >
> > > > > I have a few suggestions to the IPv4 print function too:
> > > > >
> > > > > The return value should be the number of characters written to the
> > > output string, and still -1 on error. With this modification, you could
> > > > > use the return type ssize_t instead of int32_t.
> > > > >
> > > > > Furthermore, I would prefer having the parameters in the same order
> > > as snprintf(): char *str, size_t size, const uint32_t ip_addr. Please
> > > > > also notice the suggested changed type for the size, and the const
> > > added to the ip_addr.
> > > > >
> > > > Honestly, I don't understand why we need to introduce such functions
> > > > inside DPDK at all.
> > > > What's wrong with existing standard ones: inet_ntop() and
> > > inet_pton()?
> > >
> > > Agreed, I see no added value in reinventing here
> > 
> > I think that DPDK functions for converting all sorts of types to/from strings would be useful; not only IP addresses, but also MAC addresses,
> > TCP/UDP port numbers and VLAN IDs.
> 
> For MACs we already have:
> rte_ether_format_addr()/rte_ether_unformat_addr()
> 
> > 
> > If you don't like IP address string conversion functions in the net library, DPDK could have a string conversions library. That library could
> > expose a multitude of APIs for the same purpose, so the application can use the API that best fits each application use.
> 
> I don’t mind to add new functions into net lib, if they are useful ones.
> But for that particular case, I just don't see what is the reason to
> develop and maintain our own functions while existing analogues:
> - are well known, widely adopted and field proven
> - do provide the same or even more comprehensive functionality

+1
Waiting for an answer from the authors. One month silence so far.
  
Van Haaren, Harry Jan. 19, 2022, 2:41 p.m. UTC | #9
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Wednesday, January 19, 2022 2:24 PM
> To: Morten Brørup <mb@smartsharesystems.com>; Stephen Hemminger
> <stephen@networkplumber.org>; Randles, Ronan <ronan.randles@intel.com>;
> Van Haaren, Harry <harry.van.haaren@intel.com>; Ananyev, Konstantin
> <konstantin.ananyev@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [PATCH 02/12] net: add function to pretty print IPv4
> 
> 15/12/2021 14:06, Ananyev, Konstantin:
> >
> > > > From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> > > > Sent: Wednesday, 15 December 2021 04.21
> > > >
> > > > On Wed, 15 Dec 2021 01:06:14 +0000
> > > > "Ananyev, Konstantin" <konstantin.ananyev@intel.com> wrote:
> > > > > > > --- a/lib/net/rte_ip.h
> > > > > > > +++ b/lib/net/rte_ip.h
> > > > > > > @@ -444,6 +444,26 @@ __rte_experimental
> > > > > > >  int32_t
> > > > > > >  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
> > > > > > >
> > > > > > > +
> > > > > > > +/**
> > > > > > > + * Print IP address from 32 bit int into char * buffer.
> > > > > > > + *
> > > > > > > + * @param ip_addr
> > > > > > > + *   ip address to be printed.
> > > > > > > + * @param buffer
> > > > > > > + *   The buffer the string will be saved into.
> > > > > > > + * @param buffer_size
> > > > > > > + *   size of buffer to be used.
> > > > > > > + *
> > > > > > > + * @retval 0
> > > > > > > + *   Success.
> > > > > > > + * @retval -1
> > > > > > > + *   Failure due to invalid input arguments.
> > > > > > > + */
> > > > > > > +__rte_experimental
> > > > > > > +int32_t
> > > > > > > +rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t
> > > > > > > buffer_size);
> > > > > > > +
> > > > > >
> > > > > > In continuation of my email reply about the IPv4 parse function...
> > > > > >
> > > > > > I have a few suggestions to the IPv4 print function too:
> > > > > >
> > > > > > The return value should be the number of characters written to the
> > > > output string, and still -1 on error. With this modification, you could
> > > > > > use the return type ssize_t instead of int32_t.
> > > > > >
> > > > > > Furthermore, I would prefer having the parameters in the same order
> > > > as snprintf(): char *str, size_t size, const uint32_t ip_addr. Please
> > > > > > also notice the suggested changed type for the size, and the const
> > > > added to the ip_addr.
> > > > > >
> > > > > Honestly, I don't understand why we need to introduce such functions
> > > > > inside DPDK at all.
> > > > > What's wrong with existing standard ones: inet_ntop() and
> > > > inet_pton()?
> > > >
> > > > Agreed, I see no added value in reinventing here
> > >
> > > I think that DPDK functions for converting all sorts of types to/from strings
> would be useful; not only IP addresses, but also MAC addresses,
> > > TCP/UDP port numbers and VLAN IDs.
> >
> > For MACs we already have:
> > rte_ether_format_addr()/rte_ether_unformat_addr()
> >
> > >
> > > If you don't like IP address string conversion functions in the net library, DPDK
> could have a string conversions library. That library could
> > > expose a multitude of APIs for the same purpose, so the application can use
> the API that best fits each application use.
> >
> > I don’t mind to add new functions into net lib, if they are useful ones.
> > But for that particular case, I just don't see what is the reason to
> > develop and maintain our own functions while existing analogues:
> > - are well known, widely adopted and field proven
> > - do provide the same or even more comprehensive functionality
> 
> +1
> Waiting for an answer from the authors. One month silence so far.

Hi All,

Ronan and I are working on a V2 patchset, and hope to share it in the next days.

Personally I think there is value in DPDK having various functionality "built in", and
if that functionality is available for e.g. Ether, I see no reason why IPv4 or other
protocols shouldn't have that functionality available. If I was a newcomer to DPDK,
I would find it difficult to understand why I can format/unformat Ether with DPDK,
but had to use Linux/Windows functions to format/unformat IP/UDP.

I liked Morten's feedback around real-world usage, however we have not got around
to implementing that functionality in the V2 patchset. We intended to propose that
change in signature/extra-functionality being added to V3.

I believe the gen library was discussed briefly at last tech-board call (unfortunately I was not
available to participate). Perhaps a quick chat/discussion at the next tech-board would be helpful
to identify community stance on the library? At that point the V2 should be available too.

Regards, -Harry
  

Patch

diff --git a/app/test/test_net.c b/app/test/test_net.c
index 2cb7d3e1c9..75beeea671 100644
--- a/app/test/test_net.c
+++ b/app/test/test_net.c
@@ -46,7 +46,32 @@  test_rte_ip_parse_addr(void)
 				return -1;
 		}
 	}
+	return 0;
+}
+
+static int
+test_rte_ip_print_addr(void)
+{
+	printf("Running IP printing tests...\n");
+	char buffer[128];
 
+	struct ip_str_t {
+		uint32_t ip_addr;
+		const char *exp_output;
+	} ip_str_tests[] = {
+		{ .ip_addr = 16909060, .exp_output = "1.2.3.4"},
+		{ .ip_addr = 3232301055, . exp_output = "192.168.255.255"},
+		{ .ip_addr = 2886729737, .exp_output = "172.16.0.9"}
+	};
+
+	uint32_t i;
+	for (i = 0; i < RTE_DIM(ip_str_tests); i++) {
+		int32_t err = rte_ip_print_addr(ip_str_tests[i].ip_addr,
+								buffer, 128);
+
+		if (err || strcmp(buffer, ip_str_tests[i].exp_output))
+			return -1;
+	}
 
 	return 0;
 }
@@ -55,6 +80,7 @@  static int
 test_net_tests(void)
 {
 	int ret = test_rte_ip_parse_addr();
+	ret += test_rte_ip_print_addr();
 	return ret;
 }
 
diff --git a/lib/net/rte_ip.c b/lib/net/rte_ip.c
index b859dfb640..fbd9161317 100644
--- a/lib/net/rte_ip.c
+++ b/lib/net/rte_ip.c
@@ -41,3 +41,18 @@  rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr)
 	free(tok);
 	return ret;
 }
+
+int32_t
+rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t buffer_size)
+{
+	if (buffer == NULL)
+		return -1;
+
+	snprintf(buffer, buffer_size, "%u.%u.%u.%u",
+		(ip_addr >> 24),
+		(ip_addr >> 16) & UINT8_MAX,
+		(ip_addr >> 8) & UINT8_MAX,
+		 ip_addr & UINT8_MAX);
+
+	return 0;
+}
diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
index 188054fda4..e46f0b41ba 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip.h
@@ -444,6 +444,26 @@  __rte_experimental
 int32_t
 rte_ip_parse_addr(const char *src_ip, uint32_t *output_addr);
 
+
+/**
+ * Print IP address from 32 bit int into char * buffer.
+ *
+ * @param ip_addr
+ *   ip address to be printed.
+ * @param buffer
+ *   The buffer the string will be saved into.
+ * @param buffer_size
+ *   size of buffer to be used.
+ *
+ * @retval 0
+ *   Success.
+ * @retval -1
+ *   Failure due to invalid input arguments.
+ */
+__rte_experimental
+int32_t
+rte_ip_print_addr(uint32_t ip_addr, char *buffer, uint32_t buffer_size);
+
 /**
  * IPv6 Header
  */
diff --git a/lib/net/version.map b/lib/net/version.map
index 3e5a307e48..25028f28ff 100644
--- a/lib/net/version.map
+++ b/lib/net/version.map
@@ -19,4 +19,5 @@  EXPERIMENTAL {
 	rte_net_skip_ip6_ext;
 	rte_ether_unformat_addr;
 	rte_ip_parse_addr;
+	rte_ip_print_addr;
 };