Skip to content

Commit 536b1df

Browse files
committed
Fix bug in IP wildcarding.
According to the OpenFlow specification, the mask on nw_src and nw_dst fields is not a description of how many bits to match, but rather a description of how many bits to mask. Hence, /0 is exact match and /32 is a total wildcard. We had this backwards in the OpenFlow0x01 controller. This pull requests fixes the bug.
1 parent 4ebd865 commit 536b1df

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/SDN_OpenFlow0x01.ml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,22 @@ let from_pattern (pat : AL.Pattern.t) : Core.pattern =
4949
; Core.dlVlanPcp = pat.AL.Pattern.dlVlanPcp
5050
; Core.nwSrc = (match pat.AL.Pattern.nwSrc with
5151
| None -> None
52-
| Some (p,m) -> let mo = if m = 32l then None else Some m in
52+
| Some (p,m) ->
53+
let mo =
54+
if m = 32l then
55+
None
56+
else
57+
Some (Int32.sub 32l m) in
5358
Some { Core.m_value = p; Core.m_mask = mo })
5459
; Core.nwDst = (match pat.AL.Pattern.nwDst with
5560
| None -> None
56-
| Some (p,m) -> let mo = if m = 32l then None else Some m in
57-
Some { Core.m_value = p; Core.m_mask = mo })
61+
| Some (p,m) ->
62+
let mo =
63+
if m = 32l then
64+
None
65+
else
66+
Some (Int32.sub 32l m) in
67+
Some { Core.m_value = p; Core.m_mask = mo })
5868
; Core.nwProto = pat.AL.Pattern.nwProto
5969
; Core.nwTos = None
6070
; Core.tpSrc = pat.AL.Pattern.tpSrc

0 commit comments

Comments
 (0)