What is the dot (.) in an Nftables rule - nftables

In many nftables examples, I sometimes see statement like this:
map nat-udp-services {
type ipv4_addr . inet_service : verdict
}
and this:
ip daddr . udp dport vmap #nat-udp-services
What does the dot (.) mean in these cases?

Concatenation
There's some more details about it in the wiki

Related

How to escape the . when using dot notation commandline arguments

I want to pass in a config like:
foo
blah.bar: blah.bar
another.thing: some.thing
And I want to do this on the commmandline, osmething like:
python my_script.py foo.blah.bar=blah.bar foo.another.thing=some.thing
Obviously, this would give me instead:
foo
blah
bar: blah.bar
another
thing: some.thing
... which is not what I want. How can I escape any periods (.) when using dot notation with omegaconf.OmegaConf.from_cli() ?
Based on the comment here, I think you could do something like:
python my_script.py foo[blah.bar]=blah.bar foo[another.thing]=some.thing
But I've never used omegaconf, so please don't beat me up for guessing :)
This is not supported.
You can file a feature request but it's not going to be high pri. I suggest that you use a different separator in your keys.

Method to identify ipv4 vs ipv6 addresses

I have an ip field in a postgres database defined as an inet field.
At the moment, to determine ipv4 vs ipv6, it looks like I can use colon count and/or '.' count to some degree, but there must be a better way, right?
COLON_COUNT = (length(ip::text) - length(replace(ip::text, ':', '')));
DOT_COUNT = (length(ip::text) - length(replace(ip::text, '.', '')));
What is a clean/good way to determine if a address is ipv4 or ipv6?
Use the family() function. IPv4 will return 4, IPv6 will return 6.
I think if the trailing zeros are not ommitted you could just convert the field into a number and see if the number is less than 2 powers 32 IPv4 or not (IPV6).This means filtering out colons and dots before the number conversion.

Perl: Split IP address into hostid and netid

Simple enough, I'd like to split a given IP address into netid (as defined by the netmask) and the hostid in Perl. Example:
$network = NetAddr::IP->new('192.168.255.255/29') || die "invalid space $_";
Now $network->mask returns 255.255.255.248. But there're no methods in NetAddr::IP to apply the mask to split the address into its netid and hostid portions in the /29 space.
NetAddr::IP::Util mentions the operators to do so, but it's documentation is a mess.
At least the netid can be extracted using Net::NetMask:
$netid = Net::Netmask->new('192.168.255.255/29')->base;
This yields 192.168.255.248. Again, no method to get the host portion 0.0.0.7. Maybe the best would be to pack/unpack the IPs into 32 bit int and then simply & them out. Then it would be easier to print the binary representations of IP addresses too, which I found can be really helpful for debugging and documentation purposes.
Use the hostmask() method
$host_wildcard = Net::Netmask->new('192.168.255.255/29')->hostmask;

Adding special character at several places in a string in perl script

I read some raw data from my device. This data contains the IP address as well but in a different format. As you know the IP address is generally written in the format a.b.c.d. However I have data of the format abcd given from the device. I need to get this in the format a.b.c.d How do I do this in a perl script?
Regards
First, let us split the hex string into substrings of two characters:
... split /..\K/, "c0a80001";
We treat each fragment as a hex string, and get the numeric value with the hex builtin:
... map hex, ...
Then, we join all numbers with a period:
join '.', ...
Combined:
my $ip = join '.', map hex, split /..\K/, "c0a80001";
print "$ip\n";
Output: 192.168.0.1. This is the usual text representation for an IPv4 address.
There are many ways. This inserts dots with substring.
map { substr($string,$_,0)='.' } (6,4,2);
Maybe you prefer regexes.
$string =~ s/[0-9a-f]{2}\K(?!\Z)/./g;
It really depends on the approach taken, but mostly you would need to escape with a backslash the dot from the IP address
a\.b\.c\.d
Some source code with be nice btw ...

Can I use v-strings for IPv4 addresses?

The camel book suggests that V-strings can be used for representing IPv4 addresses:
$ipaddr = 204.148.40.9; # the IPv4 address of oreilly.com
But perldata on the topic of Version Strings states:
Note that using the v-strings for IPv4
addresses is not portable unless you
also use the inet_aton()/inet_ntoa()
routines of the Socket package.
I have two questions:
1) Why is using the v-strings not portable?
2) What's the "standard" way to convert an ip-address from dotted notation to integer? Seems that unpack "N", <v-string> can cause problems sometimes.
The "standard" way to get the encoded form is inet_aton, which handles dotted IP addresses as well as hostnames -- but what do you need it for? More often than not the best idea is just to skip all of the low-level interfaces that deal with such things and use, e.g., IO::Socket.
If you're looking to convert to integer, as you say, and not to the form that socket functions expect (they're similar concepts in C, but less so in Perl), then you can go ahead and use pack just fine as long as you're consistent -- the part that's unportable is the format that socket functions accept. For example, unpack "N", pack "C4", split /\./, "1.2.3.4" will get you a nice unsigned big-endian representation of that address (in the form of the number 16909060 == 0x01020304).