Many planes were armed with 20mm cannon.....look at how many subs were either sunk or damaged to the point where they had to return to base.
The subs hull was a pressure hull, and once pearced, unable to dive to any great depth and thus....extremely vulnerable.