Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compress_ipv6 fd0e:2146:5cf5:4560::0001: expected fd0e:2146:5cf5:4560::1, got fd0e:2146:5cf5:4560::0:1 #6

Open
mgrant0 opened this issue Sep 4, 2020 · 0 comments

Comments

@mgrant0
Copy link

mgrant0 commented Sep 4, 2020

  1. in compress, you should expand the ip address first in case it's not really fully expanded
  2. you're missing a 0:0:0 case

Here's a context diff for the fix, (sorry i didn't fork this and submit a merge):

diff -c wg-ip.orig wg-ip
*** wg-ip.orig  2020-09-04 15:36:42.466694574 -0400
--- wg-ip       2020-09-04 15:36:13.723316668 -0400
***************
*** 180,185 ****
--- 180,188 ----
  # unit tests for expand_ipv6
  test_expand_ipv6(){
        tests=" \
+               fd0e:2146:5cf5:4560::0001               fd0e:2146:5cf5:4560:0000:0000:0000:0001 \
+               fd0e:2146:5cf5:4560::0000:0001          fd0e:2146:5cf5:4560:0000:0000:0000:0001 \
+               fd0e:2146:5cf5:4560::0000:0000:0001     fd0e:2146:5cf5:4560:0000:0000:0000:0001 \
                2001:db8::2:1        2001:0db8:0000:0000:0000:0000:0002:0001 \
                2001:db8:0:1:1:1:1:1 2001:0db8:0000:0001:0001:0001:0001:0001 \
                2001:db8::1:0:0:1    2001:0db8:0000:0000:0001:0000:0000:0001 \
***************
*** 204,210 ****

  # returns a compressed ipv6 address under the form recommended by RFC5952
  compress_ipv6() {
!       ip=$1

        blocks=$(echo $ip | grep -o "[0-9a-f]\+")
        set $blocks
--- 207,213 ----

  # returns a compressed ipv6 address under the form recommended by RFC5952
  compress_ipv6() {
!       ip="$(expand_ipv6 $1)"

        blocks=$(echo $ip | grep -o "[0-9a-f]\+")
        set $blocks
***************
*** 223,228 ****
--- 226,232 ----
                        :0:0:0:0:0:0 \
                        :0:0:0:0:0 \
                        :0:0:0:0 \
+                       :0:0:0 \
                        :0:0; do
                if echo $ip | grep -qs $pattern; then
                        ip=$(echo $ip | sed "s/$pattern/::/")
***************
*** 241,246 ****
--- 245,254 ----
  # unit tests for compress_ipv6
  test_compress_ipv6(){
        tests=" \
+               fd0e:2146:5cf5:4560::0001               fd0e:2146:5cf5:4560::1 \
+               fd0e:2146:5cf5:4560::0000:0001          fd0e:2146:5cf5:4560::1 \
+               fd0e:2146:5cf5:4560::0000:0000:0001     fd0e:2146:5cf5:4560::1 \
+               fd0e:2146:5cf5:4560:0000:0000:0000:0001 fd0e:2146:5cf5:4560::1 \
                2001:0db8:0000:0000:0000:0000:0002:0001 2001:db8::2:1        \
                2001:0db8:0000:0001:0001:0001:0001:0001 2001:db8:0:1:1:1:1:1 \
                2001:0db8:0000:0000:0001:0000:0000:0001 2001:db8::1:0:0:1    \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant