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

Issue with sort / reverse sort option #103

Closed
ehsandeep opened this issue Sep 12, 2022 · 1 comment · Fixed by #104
Closed

Issue with sort / reverse sort option #103

ehsandeep opened this issue Sep 12, 2022 · 1 comment · Fixed by #104
Labels
Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@ehsandeep
Copy link
Member

Describe the bug
When -s or -sr flag is used, it looks like -a option is used internally, and sorting/reverse sorting is performed on the aggregated data, whereas default sorting and reverse sorting need to performed on the expanded IPs.

Mapcidr version
master

$ cat input.txt

1.1.1.1
8.8.8.8
255.255.255.255
2.2.2.2
2.4.4.4
2.4.3.2
9.9.9.9

Current:

cat input.txt | mapcidr -s

1.1.1.1/32
2.2.2.2/32
2.4.3.2/32
2.4.4.4/32
8.8.8.8/32
9.9.9.9/32
255.255.255.255/32

Expected:

cat input.txt | mapcidr -s

1.1.1.1
2.2.2.2
2.4.3.2
2.4.4.4
8.8.8.8
9.9.9.9
255.255.255.255
@ShubhamRasal
Copy link
Contributor

#104

@ehsandeep ehsandeep linked a pull request Sep 14, 2022 that will close this issue
ehsandeep added a commit that referenced this issue Sep 14, 2022
* Add IP range input support (ipv4, ipv6) #98

- Update main.go to accept IP range from stdin and print the possible
  CIDRs

* Add test cases to validate RangeTOCIDR function

- Add test case for singleCIDR, multipleCIDRs and ip6 range.
- Convert the []net.IPNet to []string before comparing the expected.

* Add check to validate the IP range and Update README

- Accept the list of IP ranges
- Fatal() if the first IP is greater than last IP
- Fatal() if IP range contains more than 2 values.
- Update README.md to add the ip range input documentation.

* Update IP range functionality to accept only single range

- Remove the unnecessary for loop.
- Update the READ.md to remove the IP range list block

* Remove the IP comparing logic to a function

- Add new function `GetCIDRFromIPRange` which validate the input
  If input is wrong send the error otherwise returns the sorted list
  of CIDR ranges.
- Update the test case to test `GetCIDRFromIPRange` function.
- Add the wrong input IP range test case.
- Remove the IP comparing and sorting logic from main.go

* Remove the typo

* Update code to handle the IP range expansion

- Update the `main.go` to handle the case to IP range expansion
- rename the `CIDRFromIPRange` to `IPRangeInput`
- Add the if block which handles the case when Input is IP range.

* Remove old cidrs before appending new cidrs in allCidrs

* Move logic to common function to avoid repetition. Do not overwrite
allCidrs list instead use a separate net.IP list.

* Add tests for process function,

* Break wg.Add(2) into two wg.Add(1)

* Make wg.Done as defer

* Handle case of multiple IP range, combination of CIDR and IP range

- Input may contain the multiple CIDRs and multiple IP ranges
  eg. `166.8.0.0/16,166.11.0.0/16,166.9.0.0-166.10.255.255`
- Handle the above input for arggregation, count, etc
- Move the string split logic from `main()` to `process()` function
- Add the new variable IPRangeMap which stores multiple IP range

* Add the comment for ipRange block

* Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.
Replace ipRangeMap to ipRangeList.

- map key is not being used so dropped the map implementation.

* Resolve the requested changes

- Remove the IPRangeInput variable
- Simplify checking len of IPRange Input
- Use require package for checking expected and got in test cases

* Replace string.Equal to require package for testing

* Update goflags version

- mapcidr and goflag had conflicting version to solve that update the
  goflags version

* Update sorting behaviour

- Expand the CIDR then sort
- Before it was converting IPs to CIDR then sort.
- Add `getIPList()` which expands the CIDRs to IP for sorting

* Remove the unnecessary err block

Co-authored-by: Sandeep Singh <[email protected]>
Co-authored-by: Jaideep Khandelwal <[email protected]>
Co-authored-by: Siddharth Shashikar <[email protected]>
@ehsandeep ehsandeep added Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. labels Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants