-- network interface sysfs locations ordered by their pci bus address.
-- if address can't be worked out, iface gets put towards the end of the list.
sysfsnetOrderedContents =
  order =<< sysfsnetContents where
  order faces = map snd . sortBy (comparing fst) <$> weightedFaces
    where
      weightedFaces = mapM (\f -> (,) <$> weight f <*> pure f) faces

  weight face = f <$> ifacePciBusAddr face where
    f Nothing = 0xfffffffff
    f (Just (BDF a b c d)) =
              (a `shiftL` 20)
          .|. (b `shiftL` 12)
          .|. (c `shiftL` 4)
          .|.  d

-- try to work out pci bus address of network interface from its sysfs path
sysfsnetOrderedContents =
  order =<< sysfsnetContents where
  order faces = map snd . sortBy (comparing fst) <$> weightedFaces
    where
      weightedFaces = mapM (\f -> (,) <$> weight f <*> pure f) faces

  weight face = f <$> ifacePciBusAddr face where
    f Nothing = 0xfffffffff
    f (Just (BDF a b c d)) =
              (a `shiftL` 20)
          .|. (b `shiftL` 12)
          .|. (c `shiftL` 4)
          .|.  d

-- try to work out pci bus address of network interface from its sysfs path
sysfsnetOrderedContents =
  order =<< sysfsnetContents where
  order faces = map snd . sortBy (comparing fst) <$> weightedFaces
    where
      weightedFaces = mapM (\f -> (,) <$> weight f <*> pure f) faces

  weight face = f <$> ifacePciBusAddr face where
    f Nothing = 0xfffffffff
    f (Just (BDF a b c d)) =
              (a `shiftL` 20)
          .|. (b `shiftL` 12)
          .|. (c `shiftL` 4)
          .|.  d

-- try to work out pci bus address of network interface from its sysfs path