Both ... also a singlet. It's from the English word "flannel".
The Oxford Swahili dictionary says:
vazi linalovaliwa ndani ya shati au kanzu.
vazi la kitambaa lililofumwa k.v. kwa pamba au sufu ambalo huvaliwa kama shati.
Which translated means
a garment worn inside a shirt or robe
a garment of knitted/woven cloth, such as cotton or wool, which is worn as a shirt
I think it's basically any soft top covering. If you want to specify that it's an undershirt you can say fulana ya ndani. If you want to specify that it's a t-shirt, you can say fulana yenye mikono (a fulana with arms). A fulana isiyo na mikono is a sleeveless one. If you want to say "sweater", there's also the word sweta or suweta to make it clear.